libtorch编译和使用

1.0 安装cmake 3.15

Ubuntu16.04安装高版本CMake_华der的博客-CSDN博客

2.0 安装opencv

Linux源码编译安装OpenCV4(Ubuntu等)-阿里云开发者社区

3.0 编译安装libtorch 

 libtorch编译C++版本 | 码农家园

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的理解

cmake入门03 -自定义find外部库

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"
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值