Include header path change from Windows to Linux

前端 未结 6 962
终归单人心
终归单人心 2020-12-10 05:08

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

6条回答
  •  無奈伤痛
    2020-12-10 06:12

    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:

    perl -i.bak -pe "tr!\\!/! if /^\s*#\s*include\b/" myfile.cpp
    

    (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:

    for %f in (*.cpp) do perl -i.bak -pe "tr!\\!/! if /^\s*#\s*include\b/" %f
    

    The corresponding command for a Bourne shell environment (typical Linux shell):

    for f in *.cpp; do perl -i.bak -pe 'tr!\\!/! if /^\s*#\s*include\b/' $f; done
    

    If you don't have Perl installed, you should be able to find a text editor that allows search and replace across files.

提交回复
热议问题