简体   繁体   中英

GCC, linking libraries, not found?

  • OS: Windows 7 Pro X64
  • IDE: Eclipse IDE for C/C++ Developers
  • Compiler: MinGW (lastest, 4.5.2)

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.ac:/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.

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; ie 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.

尝试这个:

gcc -LC:\rhino\data\libs -LC:\rhino\data\lib -oTestC.exe TestC.o -lglfw libglfw.a libglfwdll.a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM