链接错误提升库
Linking error Boost libraries
我在这里用指南构建了 BOOST 库:http://www.boost.org/doc/libs/1_65_1/more/getting_started/unix-variants.html然后我想编译以下代码:
#include <boost/timer/timer.hpp>
#include <cmath>
int main()
{
boost::timer::auto_cpu_timer t;
for (long i = 0; i < 100000000; ++i)
std::sqrt(123.456L); // burn some time
return 0;
}
我在终端中发出了以下命令
$ c++ -o program main.cpp -I /Users/miszo97/Desktop/boost_1_65_0 -L /Users/miszo97/Desktop/boost_1_65_0/stage/lib
然后它屈服了
Undefined symbols for architecture x86_64:
"boost::timer::auto_cpu_timer::auto_cpu_timer(short)", referenced from:
_main in main-a716e4.o
"boost::timer::auto_cpu_timer::~auto_cpu_timer()", referenced from:
_main in main-a716e4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我想链接出了点问题。也许单独编译的 Boost 库没有正确构建?
有两个主要选项用于链接。
首先是-L
选项,它添加一个目录来搜索库。
器不知道要自动链接哪些库,它不会遍历所有可能的库来找到匹配的库。这就是第二个选项的用武之地:-l
(小写L)选项,它告诉链接器与特定库链接。
-l
指定的库只是库名称,而不是完整的文件名,链接器使用-L
添加的路径来查找它们。
在使用 Boost 计时器库的情况下,库名称应boost_timer
,因此您需要在链接时添加选项-lboost_timer
。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接