I have built a shared library under Eclipse/CDT in C++. To manage my projects tests, I would like to have in the same project the library and an executable for running tests on the library.
How can I do that please ?
I have built a shared library under Eclipse/CDT in C++. To manage my projects tests, I would like to have in the same project the library and an executable for running tests on the library.
How can I do that please ?
对于库本身,我有标准的构建设置:一个Debug
和一个Release
目标,带有-fPIC
编译选项、工件类型Shared Library
、扩展名so
和前缀lib
以及-share
链接器选项。
对于测试程序,我在同一个项目中添加了一个main.cpp文件:
#ifdef TEST_
#include <cstdlib>
#include <iostream>
#include "config.h"
using namespace std;
int main(int argc, char **argv) {
cout << "Test for project utils" << endl;
return 0;
}
#endif /* TEST_ */
我添加了一个Test
从其中复制的特定目标,DEBUG
并适用于标准可执行构建设置:禁止-fPIC
编译选项、添加-D TEST_
、修改工件类型为、禁止Executable
扩展名so
和前缀lib
、禁止-share
链接器选项。
现在,只要像往常一样构建 Debug、Release 和 Test,什么都可以独立完成。Test
目标可以很容易地更改为 sayTest-Debug
和,以便在Test-Release
安装后立即运行库自检。