Hello,
I am starting to use CodeLite and have apparently not the many experience in using IDEs, though I never had this sort of problems with visual studio. I included windows.h and the compiler not complained anything, but apparently the linker complained not to have found the reference to a function, that is:
./Debug/main.o: In function `WinMain@16':
C:/Users/Ilker/C++/Ilkers C++ Programme/Windows Programmierung/main.cpp:39: undefined reference to `GetStockObject@4'
I used the conveniencies of CodeLite and found out that this function is declared in wingdi.h, that is included with windows.h already. So I think that the according library was not found or searched for. You will know that the header apparently is found in "include" in the mingw directory, but apparrently it is not possible to find the appropriate library in the lib directory of mingw. So, apparently I did not understand all of regarding the including mechanism, at all, because I am very surprised on this situation, so I ask you:
1. Why is the (standard?) path to some headerfiles is well known to the compiler (linker?), but not the path to the corresponding libraries?? I thought with the delivery of headerfiles the corresponding libraries are also supported and their paths are set in the IDE.
2. How do I find out which library-name belongs to xxx.h? Is it xxx.lib or libxxx.a or something else? I found a libgdi32.a in the lib directory, is that the library to wingdi.h?, and if it is so, why does the linker not find it automatically? And is it possible to impose other name conventions for headerfiles and their libraries?
3. If I have to link the library manually, I din't find out yet, how to set paths for the linker for searching for those libraries.
thank you
linking libraries
-
- CodeLite Curious
- Posts: 2
- Joined: Tue Mar 16, 2010 9:02 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: linking libraries
The paths are known, but the ibraries are not. You need to specify them by your self. This is how the compiler/linker works.cilker wrote:1. Why is the (standard?) path to some headerfiles is well known to the compiler (linker?), but not the path to the corresponding libraries?? I thought with the delivery of headerfiles the corresponding libraries are also supported and their paths are set in the IDE.
Just for clarification: codelite is an IDE not a compiler, nor linker - so this is the behavior of the linker and *not* of codelite.
Also, you are wrong by saying that "headerfiles is well known to the compiler" - the *path* is known, which fies to include? this was done by *you* by adding the "incude" statement into your code.
You will to do the same for the linker.
quick search in google shows this: http://msdn.microsoft.com/en-us/library ... S.85).aspx so you need to add libGdi32.a to the linker path.
To do this:
open the project settings (right click it and select 'settings') , next select the linker tab, and in the 'Additional Libraries' add libGdi32.a
I am assuming that you are using g++/MinGW on Windows here.
See my first commentcilker wrote:2. How do I find out which library-name belongs to xxx.h? Is it xxx.lib or libxxx.a or something else? I found a libgdi32.a in the lib directory, is that the library to wingdi.h?, and if it is so, why does the linker not find it automatically? And is it possible to impose other name conventions for headerfiles and their libraries?
See my first commentcilker wrote:3. If I have to link the library manually, I din't find out yet, how to set paths for the linker for searching for those libraries.
In the future:
1) State your OS (one can guess it by reading the post, but in general this is how to post)
2) State your codelite version
3) Compiler you are using
4) And most important: are you using a self compiled binary of codelite or one of the distributed packages
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Curious
- Posts: 2
- Joined: Tue Mar 16, 2010 9:02 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: linking libraries
Thank you for your quick response!
"I am assuming that you are using g++/MinGW on Windows here."
Yes your assumptions are true, and in the future I will follow the advises you posted at the end, when I have more questions.
"I am assuming that you are using g++/MinGW on Windows here."
Yes your assumptions are true, and in the future I will follow the advises you posted at the end, when I have more questions.