我已经使用brew在macOSX10.15
上安装了boost,除了random_device之外,所有工作都很好。
我是这样写的:
#include <iostream>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/discrete_distribution.hpp>
#include <boost/random/random_device.hpp>
int main() {
boost::random::random_device rand_dev;
boost::mt19937 gen(rand_dev());
double probabilities[]{0, 0.99, 0.1, 0};
boost::random::discrete_distribution<> dist(probabilities);
std::cout << dist(gen);
return 0;
}
这是我从编译器得到的:
体系结构X86_64的未定义符号:
“boost::random::random_device::random_device()”,引用自main.cpp.o中的:_main
“boost::random::random_device::~random_device()”,引用自main.cpp.o中的:_main
“boost::random::random_device::operator()()”,引用自main.cpp.o中的:_main
ld:找不到体系结构x86_64的符号
CLANG:错误:链接器命令失败,退出代码为%1(使用-V查看调用)
我正在使用cmake链接它。 而且我在Ubuntu18
上安装了它,也出现了同样的链接错误。
这是我的cmake的一部分:
find_package(Boost 1.72)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(test_boost ${Boost_LIBRARY_DIR})
endif()
将-lboost_random作为编译器命令行参数添加到链接器输入:
g++ -o test test.cpp -lboost_random