vs2017开发C++项目,可以远程发布到linux系统上,并完成远程编译和调试。
具体怎么做呢?
第一步 在VS2017 写一个helloword 用cmake管理。
新建一个cmake工程
添加一个main.cpp
// main.cpp
#include <iostream>
int main() {
std::cout << "hello,world " << std::endl;
int param_in;
std::cin >> param_in;
std::cout << param_in << std::endl;
return 0;
}
CMakeLists.txt这么写
cmake_minimum_required (VERSION 3.8)
project ("CMakeProject1")
add_subdirectory ("CMakeProject1")
add_executable(hello_cmake main.cpp) #添加生成可执行文件
message(STATUS ${PROJECT_SOURCE_DIR} "------完成编译和链接生成可执行文件-----")
在windows编译运行验证无误后。
vs-工具-选项-跨平台-连接管理器 添加到linux的ssh连接
添加到linux的ssh连接
CMakeSettings.json参考格式
//CMakeSettings.json
{
"configurations": [
{
"name": "Linux-Debug",
"generator": "Unix Makefiles",
"remoteMachineName": "10.1.132.12", //ssh连接机器地址
"configurationType": "Release",
"remoteCMakeListsRoot": "/media/shixingya/demo/project",
"cmakeExecutable": "/usr/bin/cmake",
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"remoteBuildRoot": "/media/shixingya/demo/build",
"remoteInstallRoot": "/media/shixingya/demo/install",
"remoteCopySources": true,
"remoteCopySourcesOutputVerbosity": "Normal",
"remoteCopySourcesConcurrentCopies": "10",
"remoteCopySourcesMethod": "rsync",
"remoteCopySourcesExclusionList": [
".vs",
".git",
"buildmsvc"
],
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [
"linux_x64"
]
}
]
}
运行CMAKE生成
执行效果













网友评论