在命令行上编译c++boost测试程序
compile c++ boost test program on command line
我已经在exercisem.io注册了一个帐户,正在处理c++测试用例。试着让我的头脑围绕升压测试,我创建了这个简单的bob.cpp程序:
#include "bob.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
string s = bob::hey("Claus");
cout << s << endl;
return 0;
}
bob.h:
#include <string>
namespace bob {
std::string hey(std::string s) {
return "Hello " + s;
}
}
使用"clang++bob.cpp"在终端中编译并使用运行/a.out作品。使用此链接编写了一个升压测试:c++使用升压测试
bob_test.cpp:
#include "bob.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(greeting) {
BOOST_CHECK_EQUAL("Hello Claus", bob::hey("Claus"));
}
但当我尝试使用编译它时
~/devel/cpp/boost%>clang++ -I /opt/local/include -l boost_unit_test_framework bob_test.cpp
ld: library not found for -lboost_unit_test_framework
clang: error: linker command failed with exit code 1 (use -v to see invocation)
问候Claus
这是Yosemite上通过macports安装的Xcode 6.0.1,boost 1.56。在小牛队尝试了同样的Xcode,提高了1.55,但结果相同。
我通过更改传递给链接器的参数使其工作:
clang++ -I /opt/local/include -Wl,/opt/local/lib/libboost_unit_test_framework.a bob_test.cpp
^^^^
并提供到库的完整路径。
要启用c++11功能,请添加以下内容:
-std=c++11
您忘记了库路径:
$ clang++ -I /opt/local/include -L /opt/local/lib -l boost_unit_test_framework bob_test.cpp
^^^^^^^^^^^^^^^^^
修复后出现的链接错误表明您没有main()
函数-如果您有所有必要的样板,boost单元测试框架似乎会为您生成此函数-请参阅http://www.boost.org/doc/libs/1_40_0/libs/test/doc/html/utf/user-guide/test-organization/auto-test-suite.html详细信息,但看起来你可能需要:
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
而不是:
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
相关文章:
- 基于boost的程序的静态链接——zlib问题
- 如何将参数传递给Google基准测试程序
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- CMake 和 Visual Studio 2015 - C 编译器 cl.exe 无法编译简单的测试程序
- C++编译器 g++.exe 无法编译简单的测试程序 - 确定 CXX 编译器是否工作失败
- 如何编译和运行 vmmlib 测试程序?
- C++测试程序中的非法系统调用(对角矩阵元素程序的总和)
- 在我的测试程序中,为什么 cv::resize 不能执行,而 cvtColor 可以?
- 使用 QtCreator 构建 CUDA/C++ 测试程序时出现错误 2
- 使用 CLion 在不同文件中分离 Boost 测试套件的正确方法
- SDL 测试程序 - "No such file or directory"
- 软件定义无线电 USRP X310 的测试程序
- CMake 在尝试编译简单测试程序时失败
- 无法运行简单的 std::async 和 std::future 测试程序。错误:"has initializer but incomplete type."发生了什么?
- C 编译器无法编译简单的测试程序
- 从测试程序访问共享库中具有静态私有字段的类
- 这个boost.python程序中的错误是什么?
- CL.EXE无法编译简单的测试程序VS2017
- 由于某种原因,FSTREAM测试程序崩溃
- 在命令行上编译c++boost测试程序