gcc:链接库在与源文件相同的文件夹中 [英] gcc: Link Library In Same Folder As Source Files
问题描述
我正在尝试使用 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 -l
pt
, 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屋!