I'm porting an application written in C++ from Windows to Linux. I have a problem with the header files path. Windows uses \
and Linux uses /
. I am finding it cumbersome to change this in each and every source and header file. Is there some work around?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You people! Yes, you can, and should, always use forward slashes. I think the issue is how to get there from here!
If you have Perl installed, the following one liner will convert a C++ source file to use forward slashes, saving the original version in a file with extension
.bak
:(The above command line is for Windows; if you're using Linux or other Unix-like shell, use single quotes around the 3rd parameter instead of double quotes.)
If you have a bunch of files you need to convert, say all files ending in
.cpp
:The corresponding command for a Bourne shell environment (typical Linux shell):
If you don't have Perl installed, you should be able to find a text editor that allows search and replace across files.
Always use forward slashes in #include directives. Some operating systems / compilers require it, and Windows / Visual Studio is smart enough to handle it correctly.
Since your starting with Windows code, I'm assuming that you have Visual Studio. Use the find and replace dialog and create a regular expression that will do the substitution for you. Run the find and replace on all files.
For example, use something like this:
for your search expression and
for the replace expression (warning: untested). Run this on all files until no replacements are made. Then switch the angled brackets to quotes and repeat.
You can try this command based on previous perl command which do the work recusrively
What version of Windows are you using? As far as I know, starting with Windows XP, forward-slashes do actually work as path delimiters.
Always use forward slashes in #include paths. It is the compiler's job to map the path to whatever slash/directory scheme the underlying OS supports.
The Windows APIs has always supported forward slash as directory separator. And that is because as far back as at least DOS 3.1 it was supported as well. The problem has always been COMMAND.COM and CMD.EXE. They use forward slash as the option indicator (instead of dash as found in Unix). Never ever use backslashes for directory separators in languages where a backslash in a string is used to escape special characters.
If you lack a Unix shell, don't you have an editor that does search/replace across multiple files? Heck, write a small program to do it if you have to. Parsing C++ source code for its #include statements can't be hard.