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.
Linking is performed when the input file are object files " .o " (instead of source file " . cpp " or " . c "). GCC uses a separate linker program (called ld.exe ) to perform the linking.
Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With