开发者

Including Libraries C++

How do I properly include libraries in C++? I'm used to doing the开发者_JAVA技巧 standard libraries in C++ and my own .h files.

I'm trying to include wxWidgets or GTK+ in code::blocks and/or netbeans C/C++ plugin. I've included ALL libraries but I constantly get errors such as file not found when it is explicitly in the include!

One error: test1.cpp:1:24: wx/msw/wx.rc: No such file or directory : Yes the .h file library is included; what am I missing?

Do I need to be importing other things as well? Is there a tutorial for this? Obviously my shoddy textbook hasn't prepared me for this.


Firstly, header files are not the same thing as libraries. A header is a C++ text file containing declarations of things, while a library is a container for compiled, binary code.

When you #include a header file, the compiler/IDE needs to know where to find it. There is typically an IDE setting which tells the compiler where to look, or you can do it from the command line, normally using the -I switch. It sounds to me as if you have not set up the path to search for header files on in your IDE.


This means that test.cpp included "wx/msw/wx.rc" but that file cannot be found by your compiler. How to fix this depends on your compiler, but you need to find where wxwidgets is installed and add that to your "Include Paths" so that your compiler knows where to search for it. You can also put a more complete path to it in the include directive.

If the files are present in the same directory as test1.cpp, then probably you use the wrong kind of include. #include <...> is usually used for code that resides outside of the directory that your project is in. #include "..." is for includes inside your project directory (and then if they aren't found there, search in the same places as #include <> would).


It is quite an old question and this didn't really answer it for me.

I reinstalled wxwidgets into the root directory as someone suggested that being in a directory with a space in the name may be part of the problem.

Then I went into project > build options > search directories and removed all entries pointing to original install.

And this fixed the problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜