连接器找不到现有的静态库文件 [英] Linker cannot find existing Static Library File

查看:410
本文介绍了连接器找不到现有的静态库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C编程语言编写的Eclipse项目。我一直停留以来过两天相关链接错误的问题。我检查了各种论坛,以寻求解决方案。尝试了很多的建议,但未能解决这个问题。所以作为最后的手段,我问的问题在这里。我的主程序MotorRun.c有code这在静态库 FtMscLib_Static_LIBCMT_Release.Lib 这是利布斯在路径文件夹 C:\\ FT-项目\\ COMMON \\利布斯。我使用MinGW的gcc编译器。

当我运行makefile,它会生成一个错误:

<$p$p><$c$c>c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/bin/ld.exe:找不到-lC:\\ FT-项目\\ COMMON \\利布斯\\ FtMscLib_Static_LIBCMT_Release.Lib
collect2.exe:错误:LD返回1退出状态

通过Makefile中的code运行是

 海合会-LC:\\\\ FT-项目\\\\ \\\\常见利布斯-shared -o libRoboCopMinGW.exeSRC \\\\ MotorRun.o-lC:\\\\ FT-项目\\\\ \\\\常见\\\\利布斯FtMscLib_Static_LIBCMT_Release.Lib

通过查看执行code,我们可以看到路径和库名称已正确设置,但链接器无法找到它,这样它可以与我MotorRun.o对象文件链接库。希望有人能帮助我找到解决办法。
该方案MotorRun.c是一个非常简单的,所以我不会在这里张贴。但是,如果需要的话我可以在以后更新。在此先感谢!


解决方案

正确连接语法通常是这样的:

  -Lpath_to_library_directory -lname

在哪里库文件名(在Windows静态库)将 name.lib 。所以,你的上述连接线需要就失去了的.lib 部分。您可能还需要preFIX用另一种说法在 -l <​​/ code>参数 -static ,指示链接器搜索静态库 FtMscLib_Static_LIBCMT_Release.Lib 否则可能试图找到DLL来代替。

顺便说一句,有关于与MinGW的静态和动态链接的问题上StackOverflow的帖子堆,可以随意搜索这些也。 MinGW的网页也有关于同一主题的多次提示。

I have a Eclipse project using C programming language. I have been stuck with a problem related to linker error since two days now. I have checked various forums to find a solution. Tried a lot of the suggestions but could not resolve it. So as a last resort, i am asking question here. My main program MotorRun.c has code which calls functions in the static library FtMscLib_Static_LIBCMT_Release.Lib which is in Libs folder in the path C:\FT-Project\Common\Libs. I am using MinGW gcc compiler.

When i run the makefile, it generates an error:

c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lC:\FT-Project\Common\Libs\FtMscLib_Static_LIBCMT_Release.Lib
collect2.exe: error: ld returned 1 exit status

The code run by the makefile is

gcc "-LC:\\FT-Project\\Common\\Libs" -shared -o libRoboCopMinGW.exe "src\\MotorRun.o" "-lC:\\FT-Project\\Common\\Libs\\FtMscLib_Static_LIBCMT_Release.Lib"

By looking at the execution code, we can see that the paths and library name has been set correctly, but the linker just cannot find it so that it can link the library with my MotorRun.o object file. Hope someone can help me in finding a solution. The program MotorRun.c is a very simple one, so i am not posting it here. But if necessary i can update it later. Thanks in advance!

解决方案

The correct linker syntax is typically something like:

-Lpath_to_library_directory -lname

where the library filename (for a Windows static library) would be name.lib. So your above linker line needs to lose the .lib part. You may also need to prefix the -l argument with another argument -static, to instruct the linker to search for the static library FtMscLib_Static_LIBCMT_Release.Lib otherwise it might try to find the DLL instead.

By the way, there are heaps of posts on StackOverflow regarding the issue of static and dynamic linking with MinGW, so feel free to search for these also. The MinGW web pages also have numerous tips on the same topic.

这篇关于连接器找不到现有的静态库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆