Reputation: 2262
Compiling HelloWorld.c works; but when I try to add some external libraries it chokes.
I added the .a and .dll files to my 'Libraries'; add the path of both to PATH and Library Path. I also put the include files and configured the Include. The libraries I have are said to be compatible with win/mingw. They also have a different download for MSVC which does work.
Frustrating. The ld.exe gives the full path and obviously there and I have permissions to read/write them. I also included them without path (they are in library path and path).
I don't understand why this isn't working.
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lC:\rhino\data\lib\glfw.dll c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lC:\rhino\data\lib\libglfwdll.a c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lC:\rhino\data\lib\libglfw.a
C:\Users\rhino>dir C:\rhino\data\lib\libglfw.a
04/15/2011 05:24 PM 70,384 libglfw.a
Updated:
I've even added them to my C:\MinGW\lib path and it still can't find them.
Upvotes: 6
Views: 52100
Reputation: 454
Although this is quite old, I came across this question from a recent problem and the solution is quite different to the above, so am sharing.
In my case, due to the shell $PATH order (echo $PATH
), gcc
was using ld
from the anaconda install, and this ld
couldn't find a particular library.
Just changing the path order solved it:
export PATH=/usr/bin:$PATH
There are no harmful effects, see here.
Upvotes: 0
Reputation: 6659
Michael Burr pointed out the correct way of referencing libraries on the command line. The path to the library is given with the -L
switch, and the name of the library with the -l
switch (the name of the library being the file name, without the lib
part at the beginning, and the .a
suffix at the end).
One more thing to point out is that you're trying to link to both the static (libglfw.a) and the dynamic (glfw.dll) version of the library, which are both included in the download, at the same time. Instead, you should pick one, based on your needs/desires, and only link to that one.
Linking against the static version is straightforward. Just add -lglfw
to the command line.
To use the dynamic library, you should link against the import library for the dll (libglfwdll.a
), by using the -lglfwdll
switch, and omit the dll itself from the link command. Basically, the import library doesn't contain any object code, but only definitions; the actual code is in the dll. The dll will be dynamically linked at run time. (For this to work, the system has to be able to find the dll; i.e. it has to be in the current working directory, in a directory that is in the path, or its directory has to be added to a special environment variable used for this thing; but for this to become important, you first have to succeed in building the executable.)
Upvotes: 12
Reputation: 340426
My experience (which doesn't include how this might be configured in Eclipse) is that ld
(which gcc will invoke) wants the lib names without the lib
prefix or the .a
extension. Try:
gcc -LC:\rhino\data\libs -LC:\rhino\data\lib -oTestC.exe TestC.o -lglfw -lglfwdll
I'm not sure that the glfw.dll
file should be listed as a library; the import library for that DLL (I assume that's libglfwdll.lib) should take care of linking to the DLL.
Upvotes: 4
Reputation: 17124
Try this:
gcc -LC:\rhino\data\libs -LC:\rhino\data\lib -oTestC.exe TestC.o -lglfw libglfw.a libglfwdll.a
Upvotes: 0