我正在尝试编译一些依赖于 QuantLib 的 C++,而后者又依赖于 Boost。我正在使用 MacBook Pro M1(ARM 架构)。我使用此页面上的说明安装了 Boost 和 QuantLib:https : //www.quantlib.org/install/macosx.shtml。然后我尝试编译以下源代码:
#include <iostream>
#include <ql/quantlib.hpp>
int main(int, char*[])
{
QuantLib::Option::Type OptionType(QuantLib::Option::Call);
std::cout << "Option Type = " << OptionType << std::endl;
return 0;
}
使用以下命令:
clang++ -std=c++11 ql_ex1.cpp -o build/ql_ex1 $(INC) $(LIB) \
-I/opt/homebrew/Cellar/quantlib/1.23/include -I/opt/homebrew/Cellar/boost/1.76.0/include \
-L/opt/homebrew/Cellar/boost/1.76.0/lib -L/opt/homebrew/Cellar/quantlib/1.23/lib
这给了我以下错误消息:
Undefined symbols for architecture arm64:
"boost::assertion_failed(char const*, char const*, char const*, long)", referenced from:
long double boost::math::detail::sinpx<long double>(long double) in ql_ex1-044d3e.o
"boost::assertion_failed_msg(char const*, char const*, char const*, char const*, long)", referenced from:
boost::array<long double, 171ul>::operator[](unsigned long) const in ql_ex1-044d3e.o
...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1
到目前为止,我已经尝试了以下方法,
clang++
在仿真中运行。我看到相同的未定义符号错误。assertion_failed
符号的内容。有人可以指出我在哪里(如果有的话)这个符号的定义?知道我是否只是缺少正确的编译器选项或者是否有更基本的问题需要解决会很有用。
我认为您-lQuantLib
在命令行中缺少一个?您告诉编译器在哪里查找库(-L
开关),而不是要链接哪些库。
另外,检查自制软件是否还在quantlib-config
您的计算机上安装了脚本。如果是这样,它应该提供您需要的开关;尝试跑步
quantlib-config --cflags
它应该输出-I
指定 QuantLib 标头位置的标志(也可能是-std=c++11
您手动传递的标志),以及
quantlib-config --libs
它应该输出相应的-L
开关以及-lQuantLib
您错过的开关。
如果它们有效,您可以使用命令
clang++ ql_ex1.cpp -o build/ql_ex1 $(INC) $(LIB) \
-I/opt/homebrew/Cellar/boost/1.76.0/include \
`quantlib-config --cflags` `quantlib-config --libs`
并让脚本为您填写信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句