我正在尝试让UnitTest++在遵循以下目录树的项目中工作:
Project/
|-- src/
|-- test/
| |-- test.cpp
|-- unittest-cpp/
| |-- UnitTest++/
| |-- libUnitTest++.a
| |-- src/
| |-- UnitTest++.h
|-- Makefile我正尝试在项目目录中使用g++进行编译。我的test.cpp文件包含UnitTest++入门代码。
我尝试了以下几种方法:
g++ -Lunittest-cpp/UnitTest++/ -lUnitTest++ -Iunittest-cpp/UnitTest++/src/ \
test/test.cpp -o Test如果我理解得很好,-L就是给出静态库的路径。大写字母(小写L)表示库名称,-I (大写i)表示包含路径。
我得到了两个不同的结果。它要么告诉我在/usr/bin/??中找不到库或者它告诉我存在对unittest::*的未定义引用。
是不是因为我给了一个库的相对路径,它不能编译?我刚开始在多个目录中使用g++,我正在尝试了解它是如何工作的,然后再让它在我的Makefile中工作。
编辑:在链接库和头文件之前,必须提供test/test.cpp参数。所以,这是可行的:
g++ test/test.cpp -Lunittest-cpp/UnitTest++ -lUnitTest++ -Iunittest-cpp/UnitTest++/src -o Test发布于 2013-07-02 03:43:55
编译时,要编译的文件(在此上下文中为test.cpp)必须在其依赖项之前给出。这是可行的:
g++ test/test.cpp -Lunittest-cpp/UnitTest++ -lUnitTest++ -Iunittest-cpp/UnitTest++/src -o Testhttps://stackoverflow.com/questions/14835609
复制相似问题