Fixing #includes <> for GCC (Code::Blocks)

拜拜、爱过 提交于 2019-12-19 09:57:43

问题


I am working with some code that was written for a different compiler/linker, and it is including files like this:

#include <Engine/Graphics/Sprite.h>

from anywhere in the project.

The project contains such a file at that path (from the root of the project), but when I build I get the file not found error.

How can I fix all of these includes, without going through and doing it all manually?


回答1:


I'm not quite sure if I understand your explanation, what do you mean with "from the root of the project". But well...

When you use the #include directive with <> what your are telling the compiler is to look for the the file on the Directories you include with -I option.

In code blocks go to Project->Build Options->Search Directories->Compiler

And add the folder path to the folder containing "Engine".

You can find more info here http://msdn.microsoft.com/en-us/library/36k2cdd4(v=vs.71).aspx

Edit: Before trying anything, try #include "path/somefile.h" instead of #include <pathsomefile.h>




回答2:


Probably you should write

#include "Engine/Graphics/Sprite.h"

(notice the double quotes instead of the brackets).

In #include directives brackets are used to specify that you want to include a system/library header file, that will be searched in the system includes directory (e.g. /usr/include), while the double quotes are used to include files in the current path.

This should work if the files that use this #include are in the directory that contains the Engine/... hierarchy. If that's not the case, you should also specify it to the compiler as an additional include directory, with the -I directive.




回答3:


Please remember that one usually uses #include <filename> directive to include files from standard include catalogues. These catalogues defined as environment variable or in command line of compiler. And #include "filename" to include header file from current directory or any path relative to current directory.

without going through and doing it all manually?

You may use search&replace feature of your favourite editor




回答4:


I'm going to copy Ben's comment and say you should add an include path to where your header files are located. This is very common to do in a project



来源:https://stackoverflow.com/questions/6365014/fixing-includes-for-gcc-codeblocks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!