1.0 安装cmake 3.15
Ubuntu16.04安装高版本CMake_华der的博客-CSDN博客
2.0 安装opencv
Linux源码编译安装OpenCV4(Ubuntu等)-阿里云开发者社区
3.0 编译安装libtorch
conda 不能用了
channels:
- defaults
show_channel_urls: true
channel_alias: http://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
ubuntu 源码编译libtorch_ubuntu 编译libtorch
https://www.cxyzjd.com/article/yang332233/105853230
如何在cmakelist中,find_package取指定路径中查找_cmkelists中find package写入库的路径_Feiyang_luo的博客-CSDN博客
pc文件和Config.cmake的理解
3.10 检测外部库:Ⅱ. 自定义find模块 · cmake-cookbook · 看云
https://www.cnblogs.com/narjaja/p/9533199.html
https://brightxiaohan.github.io/CMakeTutorial/FindPackage/
成功demo
libtorch编译C++版本_libtorch 编译_hanqu3456的博客-CSDN博客
如何在cmakelist中,find_package取指定路径中查找_cmkelists中find package写入库的路径_Feiyang_luo的博客-CSDN博客
LD_LIBRARY_PATH与-L的关系以及延伸_51CTO博客_LD_LIBRARY_PATH
demo.cpp
#include <iostream>
#include <vector>
#include <string>
#include <torch/script.h> // One-stop header.
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/work/code/hwy-pnc/test/pytorch/torch/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
launch.json
{
"configurations": [
{
"name": "C/C++: g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"externalConsole": false,
"environment": [{ "name": "LD_LIBRARY_PATH", "value": "/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/work/code/hwy-pnc/test/pytorch/torch/lib" }],
"MIMode": "gdb",
/*
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
*/
"preLaunchTask": "C/C++: g++ build active file"
}
],
"version": "2.0.0"
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",//,
"-D_GLIBCXX_USE_CXX11_ABI=1",
"-I",
"/work/code/hwy-pnc/test/pytorch/torch/include",
"-I",
"/work/code/hwy-pnc/test/pytorch/torch/include/torch/csrc/api/include",
"-L",
"/work/code/hwy-pnc/test/pytorch/torch/lib",
"-l","torch_cpu",
//"-l","torch_library",
"-l","c10_cuda",
"-L",
"/usr/local/cuda/lib64",
"-l","nvrtc",
"-l","nvToolsExt",
"-l","cudart",
"-L",
"/usr/local/cuda/lib64/stubs",
"-l", "cuda",
"-l", "c10",
"-l","kineto",
// "`pkg-config","--libs","--cflags","torch`",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger.",
}
],
"version": "2.0.0"
}