1. 展示目录结构
注意: 每一层级目录都需要编写CMakeLists.txt文件
2. 创建父目录main.cpp文件
#include "./lib/detect_head.h"
#include "./lib/api.cpp"
using namespace std;
int main()
{
test();
}
3. 创建父目录CMakeLists.txt文件
# 项目名称
PROJECT(HELLO_VERSION_1.0)
# 生成的动态文件在bin目录中
ADD_SUBDIRECTORY(./lib bin)
# 可执行程序
ADD_EXECUTABLE(hello main.cpp)
# 添加链接库 a|so
TARGET_LINK_LIBRARIES(test)
4. 创建头文件和api文件
// ************* detect_head.h *************
#include <iostream>
using namespace std;
void test();
// ************* api.cpp *************
#include "detect_head.h"
void test()
{
printf("test \n ");
}
5. 创建lib目录CMakeLists.txt文件
SET(HELLO_LIB ./api.cpp)
ADD_LIBRARY(test SHARED ${HELLO_LIB})
6. 创建shell脚本
mkdir build
cd build
cmake ..
make -j
7. 完结 - 效果
注:./build/bin/lib***.so文件 即可进行二次开发