Compiling HelloWorld.c works; but when I
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.)
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.
Try this:
gcc -LC:\rhino\data\libs -LC:\rhino\data\lib -oTestC.exe TestC.o -lglfw libglfw.a libglfwdll.a