赞
踩
1 openVINO下有个demos,里面是一个总工程,如果对单个demo研究势必要从总工程拿出来,否则不好调试。这里以human_pose_estimation_demo为例,看看如何从零开始搭建openVINO工程
2 这里选择Makefile作为编译手段。
3 重要的位置已经加粗,红色字体或注意两字,请悉知
上一节,我分享了用gcc/g++方式完成。可以参考
https://blog.csdn.net/weixin_39956356/article/details/107246477
上一节,我分享了用cmake方式完成。可以参考:
https://blog.csdn.net/weixin_39956356/article/details/107282625
详细的基本概念务必看,可以参考
https://blog.csdn.net/weixin_39956356/article/details/107246477
这里可以不需要tasks.json,也可以加上
这三部分内容请参考上面的文章。Makefile方式很简单,主要是写出Makefile。,为此我写了一个简单的Makefile。
目标是这个,很简单。
注意:这里提前新建obj,bin文件夹,obj存放中间文件,bin存放目标文件。
注意:clean
仅仅是清除obj下的文件
#$(shell mkdir obj bin) # 需要新建这些文件夹 DIR_INC = ./include INFERENCE_ENGINE_INC = /opt/intel/openvino/deployment_tools/inference_engine/include OPENCV_INC = /opt/intel/openvino/opencv/include COMMON_INC = ../common/ GFLAGS_INC = ../thirdparty/gflags/include OPENCV_LIB = /opt/intel/openvino/opencv/lib INFERENCE_ENGINE_LIB = /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64 DIR_SRC = ./src DIR_OBJ = ./obj DIR_BIN = ./bin # 取出所有的.cpp SRC = $(wildcard ${DIR_SRC}/*.cpp) # notdir:去除路径, patsubst,$(patsubst <pattern>,<replacement>,<text>),从<text>查找模式<pattern>,ok就替换成<replacement> OBJ = $(patsubst %.cpp, ${DIR_OBJ}/%.o, $(notdir ${SRC})) # 输出只支持warning和error $(warning ${SRC}) $(warning ${OBJ}) TARGET = main BIN_TARGET = ${DIR_BIN}/${TARGET} CXXFLAGS = -std=c++11 -g -Wall -pthread -I${DIR_INC} -I${COMMON_INC} -I${INFERENCE_ENGINE_INC} -I${OPENCV_INC} -I${GFLAGS_INC} LDFLAGS = -L${OPENCV_LIB} -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_videoio -L${INFERENCE_ENGINE_LIB} -linference_engine -linference_engine_c_api -linference_engine_legacy -linference_engine_nn_builder ../thirdparty/gflags/lib/Debug/libgflags_nothreads.a ../thirdparty/gflags/lib/Debug/libgflags_nothreads.a ${BIN_TARGET}:${OBJ} $(CXX) $(OBJ) ${LDFLAGS} -o $@ ${DIR_OBJ}/%.o:${DIR_SRC}/%.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ .PHONY: clean clean: -rm -rf ${DIR_OBJ}/*.o
下图是一个目标样例,为了更好管理文件,就多新建了bin和obj
tasks.json是编译用的,单词是复数可以有多个任务。下面就写一个tasks.json。
注意这个tasks.jon的任务是调用make取编译,因此不需要选择什么活动文件,让vscode推测我们的意图了。
注意:选择others
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
“version”: “2.0.0”,
“tasks”: [
// task 1, make -j
{
“label”: “build”,
“type”: “shell”,
“command”: “make”,
“args”: ["-j"]
},
// task 2, make clean
{
“label”: “clean”,
“type”: “shell”,
“command”: “make”,
“args”: [“clean”],
}
]
}
注意:上面我就简单的建立了两个任务,很简单,一个是make -j
和make clean
注意:其中 "label":
是它的名字,一个叫build,另一个是clean
其实没有必要新建两个task,因为下方有shell,直接执行命令即可
你到底是希望vscode先编译成可执行文件之后调试, 还是已经有了可执行程序,只需要调试。毫无疑问,这里是后者,因为make已经完成了编译,并且可执行程序是bin/main。这种做法,就和cmake工程想法一模一样了
这里选择Makefile作为活动文件即可。主要是不要有preLaunchTask
,请参考上面的文章。
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/${fileBasenameNoExtension}", "args": ["-m", "/home/wzk/intel/human-pose-estimation-0001/FP16/human-pose-estimation-0001.xml", "-d", "CPU" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
你会想,上面都可以执行了,为什么还出现红色波浪号和错误,上节并没有解释,这里一起说了,因为编译链接给计算机看的,代码给人看的,进而专门设计了c_cpp_properties.json(文件智能感知),把导航的头文件放进去,就ok了
注意主工程位置,这时就没有错误的提示
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/${fileBasenameNoExtension}", "args": ["-m", "/home/wzk/intel/human-pose-estimation-0001/FP16/human-pose-estimation-0001.xml", "-d", "CPU" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
到这里就要结束本期的三篇文章了,涉及以下内容
最后,一个问题,vscode到底给我们带来了什么便利?
答:我觉得是调试,因为编译没有vscode也可以干,比如make/cmake。难道你愿意用gdb调试大型工程?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。