GCC,链接库,没有找到?
- 操作系统:Windows 7 Pro X64
- IDE:面向 C/C++ 开发人员的 Eclipse IDE
- 编译器:MinGW(最新,4.5.2)
编译 HelloWorld.c 有效;但是当我尝试添加一些外部库时,它就卡住了。
我将 .a 和 .dll 文件添加到我的“库”中;将两者的路径添加到 PATH 和 Library Path。我还放置了包含文件并配置了包含。据说我的库与 win/mingw 兼容。他们还有一个不同的 MSVC 下载,确实有效。
令人沮丧。 ld.exe 给出了完整路径,显然我有权限读/写它们。我也将它们包含在没有路径的情况下(它们位于库路径和路径中)。
我不明白为什么这不起作用。
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: 找不到 -lC:\rhino\data\库\glfw.dll c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: 找不到 -lC:\rhino\data\ lib\libglfwdll.a c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: 找不到 -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
更新:
我什至将它们添加到我的 C:\MinGW\lib 路径中,但仍然找不到它们。
- 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.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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Michael Burr 指出了在命令行上引用库的正确方法。库的路径由
-L
开关给出,库的名称由-l
开关给出(库的名称是文件名,没有开头的lib
部分和结尾的.a
后缀)。还要指出的另一件事是,您试图同时链接到该库的静态(libglfw.a)和动态(glfw.dll)版本,它们都包含在下载中。相反,您应该根据您的需要/愿望选择一项,并且仅链接到该一项。
链接到静态版本非常简单。只需将
-lglfw
添加到命令行即可。要使用动态库,您应该使用
-lglfwdll
开关链接到 dll 的导入库 (libglfwdll.a
),并从链接命令。基本上,导入库不包含任何目标代码,而仅包含定义;实际代码在dll中。该dll将在运行时动态链接。 (为此,系统必须能够找到该 dll;即它必须位于当前工作目录、路径中的目录中,或者必须将其目录添加到使用的特殊环境变量中对于这件事;但要使其变得重要,您首先必须成功构建可执行文件。)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 thelib
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.)我的经验(不包括如何在 Eclipse 中配置)是
ld
(gcc 将调用)需要不带lib
前缀或 < code>.a 扩展名。尝试:我不确定
glfw.dll
文件是否应列为库;该 DLL 的导入库(我假设是 libglfwdll.lib)应该负责链接到该 DLL。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 thelib
prefix or the.a
extension. Try: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:
虽然这个问题已经很老了,但我在最近的一个问题中遇到了这个问题,而且解决方案与上面的完全不同,所以我分享一下。
就我而言,由于 shell $PATH 顺序 (
echo $PATH
),gcc
使用了 anaconda 安装中的ld
,并且这个 < code>ld 找不到特定的库。只需更改路径顺序即可解决问题:
没有有害影响,请参阅此处。
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 usingld
from the anaconda install, and thisld
couldn't find a particular library.Just changing the path order solved it:
There are no harmful effects, see here.