环境: gcc 5.4.0 g++ 5.4.0
头文件格式 可以添加路径 解决找不到头文件错误
#include <opencv2/opencv.hpp>
#include
#include “include/argsParser.h”
#include “include/configs.h”
#include
#include “tensorRTWrapper/code/include/YoloLayer.h”
#include “include/dataReader.h”
#include “include/eval.h”
#include “tensorRTWrapper/code/include/TrtNet.h”
c++ 文件编译命令
g++ main.cpp -fpic -shared -o libyolov3.so -std=c++11 -I/usr/local/cuda/include
main.cpp 要编译的文件
-std=c++11 指定c++版本
-I/usr/local/cuda/include 添加第三方头文件
执行完命令:生成.so文件
add_o.cpp
#include
using namespace std;
extern “C”{//在extern “C”中的函数才能被外部调用
int add(int x,int y)
{
cout<<“cpp文件已经被调用”<<endl;
return x+y;
}
void tmp()
{
cout<<add(1,2)<<endl;
}
int main()
{
tmp();
return 0;
}
} //匹配extern “C”中大括号
编译生成动态链接库so文件的命令:
g++ add_o.cpp -shared -fpic -o libadd.so
from ctypes import *
import time
def main():
start = time.time()
dll = cdll.LoadLibrary(’./libadd.so’)
dll.add(1,2)
print(“第一次调用结束”)
dll.tmp()
print(“第二次调用结束”)
print(dll.main())
print(“第三次调用结束”)
end = time.time()
print("time_total = ",end-start)
main()
到此整个生成so文件,以及调用so文件整个代码就调试通完毕