VScode配置libtorch环境(ubuntu18.04+libtorch1.7.0+pytorch1.7.0模型)

本文介绍了解决使用LibTorch编译项目时出现的路径配置错误问题。通过正确设置tasks.json、launch.json和c_cpp_properties.json文件中的路径,可以避免因路径错误导致的编译失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出现这个错误的原因是:terminate called after throwing an instance of 'c10::Error'。解答:下面三个.json里面libtorch和build的路径没有给对,是路径错误

tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "example-app",  //lauch.json preLaunchTask
			"command": "cmake",
			"args": [
				"-DCMAKE_PREFIX_PATH=/home/zxw/Documents/work/libtorch-shared-with-deps-1.7.0/libtorch",
                "-DCMAKE_BUILD_TYPE=Debug",
				"..",
				"&&",
				"make",
				"-j",
			],
			"options": {
				"cwd": "/home/zxw/Documents/work/libtorch-shared-with-deps-1.7.0/example-app/build"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			}
		}
	]
}

launch.json

{
    
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/zxw/Documents/work/libtorch-shared-with-deps-1.7.0/example-app/build/example-app",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/home/zxw/Documents/work/libtorch-shared-with-deps-1.7.0/example-app/build",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "example-app",
            "miDebuggerPath": "/usr/bin/gdb",
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "/home/zxw/Documents/work/libtorch-shared-with-deps-1.7.0/example-app/build/**",
                "/home/zxw/Documents/work/libtorch-shared-with-deps-1.7.0/libtorch/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值