GCC library link not found?

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

Compilation of works HelloWorld.c; but when I try to add some external libraries, it suffocates.

I added .a and .dll files to my "Libraries"; add the path to both PATH and the library path. I also added include files and configured Include. The libraries that I have are said to be compatible with win / mingw. They also have another download for MSVC that works.

frustrating. Ld.exe gives the full path and is obviously there, and I have read / write permissions. I also included them without a path (they are on the path and the path to the library).

I do not understand why this does not work.

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 even added them to my C: \ MinGW \ lib path and it still cannot find them.

+2
source share
3 answers

Michael Barr pointed out the correct way to link libraries on the command line. The path to the library is set using the -L switch and the library name using the -L switch (library name is the file name, without the lib part at the beginning) and .a at the end).

Another thing worth paying attention to is that you are trying to establish a link to both the static (libglfw.a) and dynamic (glfw.dll) versions of the library that are included in the download at the same time. Instead, you should choose one based on your needs / desires, and only a link to it.

The link to the static version is simple. Just add -lglfw to the command line.

To use the dynamic library, you must reference the import library for dll ( libglfwdll.a ) using the -lglfwdll switch and omit the dll itself from the link command. In principle, the import library does not contain any object code, but only a definition; the actual code is in the dll. The DLL will dynamically bind at runtime. (For this, the system must be able to find the dll, that is, it must be in the current working directory, in the directory that is in the path, or its directory must be added to the special environment variable used for this, but in order for it to become important, you need to create an executable file first.)

+5
source

My experience (which does not include how this can be configured in Eclipse) is that ld (which will call gcc) wants 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 am not sure if the glfw.dll file should be listed as a library; the import library for this DLL (I assume that libglfwdll.lib) should take care of the connection with the DLL.

+4
source

Try the following:

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

Source: https://habr.com/ru/post/1485501/


All Articles