使用ld链接器工具 [英] Using the ld linker tool

查看:249
本文介绍了使用ld链接器工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

如果我链接我的应用程序,则无法在H:\ MinGW \ lib \ gcc \ mingw32 \ 4.5.2中找到库,只能在H:\ MinGW \ lib中找到.我收到以下消息:

Hi!

If I link my application it can''t find libraries in H:\MinGW\lib\gcc\mingw32\4.5.2, only in H:\MinGW\lib. I get these messages:

ld: cannot find crtbegin.o
ld: cannot find -lstdc++
ld: cannot find -lgcc
ld: cannot find crtend.o


我需要一种适用于其他人的解决方案,因为我在文章中需要此解决方案.不使用-L选项指定完整路径怎么办?

在此先感谢


I would need a solution that works for others, because I need this for an article. How can I make it work without specify the full path with -L option?

Thanks in advance

推荐答案

只有四种方法可以指定要链接到的库的位置:

1.将库复制(或符号链接)到您的工作目录中.
2.将库复制到标准默认库目录
3.使用-L
指定库的目录路径 4.将目录路径添加到LD_LIBRARY_PATH变量.

选项#3(使用-L指定路径)通常是首选方法.

将库从其标准位置复制到其他地方(1&2)是不好的做法,因为在将新库创建/安装到原始位置后,您可能会得到过时的库.

通常不赞成在环境变量中指定其他搜索路径,因为该数据未捕获到您的makefile中.

至少如果您将路径硬编码到链接器命令中,则数据就在您的makefile中,并且很容易看出链接器在做什么.

这样,当有人尝试在其他系统上构建项目并且链接器步骤失败时,他们只需要查看链接器命令并修复库路径即可.
There is only four ways to specify the location of libraries you want to link to:

1. Copy (or symbolic link) the library into your working directory.
2. Copy the library into the standard default library directory
3. Specify the directory path for the library using -L
4. Add the directory path to the LD_LIBRARY_PATH variable.

Option #3 (specifying the path using the -L) command is generally the preferred method of doing it.

Copying the library from it''s standard place to somewhere else (1&2) is bad practice because you can end up with outdated libraries when new ones are created/installed into the original location.

Specifying additional search paths in an environmental variable is generally frowned upon because that data isn''t captured in your makefile.

At least if you hardcode a path into your linker command, the data is right there in you makefile and it''s easily seen what the linker is doing.

That way when someone tries to build the project on a different system and the linker step fails, they just have to look at the linker command and fix up the library paths.


这篇关于使用ld链接器工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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