gcc:链接库在与源文件相同的文件夹中 [英] gcc: Link Library In Same Folder As Source Files

查看:63
本文介绍了gcc:链接库在与源文件相同的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 gcc 编译 C 项目.所有源文件和.a库文件都在同一文件夹中 .如何成功编译项目?

I'm trying to compile a C project using gcc. All source files and the .a library file are in the same folder. How can I successfully compile the project?

我尝试过:

gcc -o test main.c IPT.c logitem_list.c -L -./ -libpt

但是我收到错误消息:

/usr/bin/ld: cannot find -libpt
collect2: error: ld returned 1 exit status

推荐答案

您将目录指定为 -L ,将核心"名称指定为 -l <​​/code>:

You specify the directory to -L and the 'core' name to -l:

gcc -o test main.c IPT.c logitem_list.c -L . -lpt

当给定 -l <​​/code> pt 时,链接程序将查找 libpt.a libpt.如此或等价物(扩展名如 .dylib .sl .dll .lib 其他平台).

When given -lpt, the linker looks for libpt.a or libpt.so or equivalents (extensions like .dylib or .sl or .dll or .lib on other platforms).

-L -./表示链接器在名为破折号"的目录中查找,该目录不太可能存在,也不在 libpt.a 仍然可以找到.

The -L -./ is suggesting that the linker look in a directory called 'dash dot', which is unlikely to exist and isn't where libpt.a is found anyway.

这篇关于gcc:链接库在与源文件相同的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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