visual studio 2022 远程开发:linux+cmake+vcpkg开发环境配置
liuian 2025-01-21 19:29 57 浏览
最近根据项目需求,需要搭建在widowds下 使用visual studio 2022 IDE 工具远程在Linux平台c++环境。网上查了很多资料,可供参考的资料特别少,经过多轮配置,现将配置的基本步骤分享给大家。
要求如下:
1、c++11标准
2、编译工具Cmake
3、编译器GCC
4、包管理工具Vcpkg(微软 C++ 团队开发的适用于 C 和 C++ 库的跨平台开源软件包管理器)
5、jsoncpp(一款基于c++的json三方处理库)
一、camke 安装
1、下载网址:https://cmake.org/download/
2、版本:Cmake 3.23.1
3、安装步骤
tar -zvxf cmake-3.23.1.tar.gz cd cmake-3.23.1/
./bootstrap
make & make install如出现如下提示:请安装openssl-devel
Could not find OpenSSL. Install an OpenSSL development package or
configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
rm -f CMakeCache.txt
yum -y install ncurses-devel
yum install openssl-devel二、Linux 下 vcpkg安装
1、下载网址:https://github.com/Microsoft/vcpkg
2、安装步骤
git clone https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.sh 3、设置环境变量
vi /etc/profile
export PATH=$PATH:/root/vcpkg/
source /etc/profile三、vcpkg 下 jsoncpp 安装
vcpkg integrate install
vcpkg install jsoncpp:x64-linux生成的提示信息,很重要,cmakeLists一定要按照如下配置
jsoncpp provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(jsoncpp CONFIG REQUIRED) target_link_libraries(main PRIVATE jsoncpp_object jsoncpp_static JsonCpp::JsonCpp)
这段代码加入cmakeLists.txt
四、vs2022配置
1、配置vs2022远程跨平台链接
工具->选项->跨平台->添加SSH linux服务器链接
2、新建工程
选择,Cmake项目(生成不依赖于.sln或.vcxproj支持的跨平台C++应用)
3、cmakeLists.txt配置
# CMakeList.txt: video 的 CMake 项目,在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.23.1)
project ("video")
set(CMAKE_CXX_STANDARD 11)
set(SOURCES "src/")
find_package(jsoncpp CONFIG REQUIRED)
# 用于创建可执行文件,第一个参数是可执行文件名字,第二个参数为需要用到的源文件
add_executable (video "${SOURCES}main.cpp" "${SOURCES}header/main.h" "${SOURCES}OperationVideo.cpp" "${SOURCES}header/OperationVideo.h" "${SOURCES}header/OperJson.h" "${SOURCES}OperJson.cpp")
# 用于指明构建目标的依赖库,第一个参数为构建目标,第三个参数为依赖库
target_link_libraries(video PRIVATE jsoncpp_object jsoncpp_static JsonCpp::JsonCpp)4、CmakeSettings.json配置文件如下
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"addressSanitizerEnabled": false,
"buildCommandArgs": "",
"cmakeCommandArgs": "",
"cmakeExecutable": "cmake",
"cmakeToolchain": "/root/vcpkg/scripts/buildsystems/vcpkg.cmake",
"configurationType": "Debug",
"ctestCommandArgs": "",
"generator": "Unix Makefiles",
"inheritEnvironments": [ "linux_x64" ],
"intelliSenseMode": "linux-gcc-x64",
"name": "Linux-GCC-Debug",
"remoteBuildRoot": "$HOME/vs/${projectDirName}/${workspaceHash}/out/build/${name}",
"remoteCMakeListsRoot": "$HOME/vs/${projectDirName}/${workspaceHash}/src",
"remoteCopyAdditionalIncludeDirectories": [ "/usr/local/lib/", "usr/local/include/", "/root/vcpkg/installed/x64-linux/include" ],
"remoteCopyBuildOutput": true,
"remoteCopySources": true,
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"remoteCopySourcesMethod": "rsync",
"remoteInstallRoot": "$HOME/vs/${projectDirName}/${workspaceHash}/out/install/${name}",
"remoteMachineName": "-1539221974;192.168.2.188 (username=root, port=22, authentication=Password)",
"rsyncCommandArgs": "-t --delete --delete-excluded",
"variables": [
{
"name": "_VCPKG_INSTALLED_DIR",
"value": "/root/vcpkg/installed",
"type": "PATH"
},
{
"name": "VCPKG_APPLOCAL_DEPS",
"value": "true",
"type": "BOOL"
}
]
},
{
"name": "Linux-GCC-Release",
"generator": "Unix Makefiles",
"configurationType": "RelWithDebInfo",
"cmakeExecutable": "cmake",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x64" ],
"remoteMachineName": "${defaultRemoteMachineName}",
"remoteCMakeListsRoot": "$HOME/vs/${projectDirName}/${workspaceHash}/src",
"remoteBuildRoot": "$HOME/vs/${projectDirName}/${workspaceHash}/out/build/${name}",
"remoteInstallRoot": "$HOME/vs/${projectDirName}/${workspaceHash}/out/install/${name}",
"remoteCopySources": true,
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"remoteCopySourcesMethod": "rsync"
},
{
"name": "WSL-GCC-Debug",
"generator": "Unix Makefiles",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeExecutable": "cmake",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x64" ],
"wslPath": "${defaultWSLPath}"
}
]
}
5、新建main.cpp
#include "json/json.h"
#include <iostream>
#include <memory>
/**
* \brief Parse a raw string into Value object using the CharReaderBuilder
* class, or the legacy Reader class.
* Example Usage:
* $g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString
* $./readFromString
* colin
* 20
*/
int main() {
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
const auto rawJsonLength = static_cast<int>(rawJson.length());
constexpr bool shouldUseOldWay = false;
JSONCPP_STRING err;
Json::Value root;
if (shouldUseOldWay) {
Json::Reader reader;
reader.parse(rawJson, root);
} else {
Json::CharReaderBuilder builder;
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
if (!reader->parse(rawJson.c_str(), rawJson.c_str() + rawJsonLength, &root,
&err)) {
std::cout << "error" << std::endl;
return EXIT_FAILURE;
}
}
const std::string name = root["Name"].asString();
const int age = root["Age"].asInt();
std::cout << name << std::endl;
std::cout << age << std::endl;
return EXIT_SUCCESS;
}
以上就是vs2022远程linux下开发环境配置,亲测可以用。
相关推荐
- 搭建一个20人的办公网络(适用于20多人的小型办公网络环境)
-
楼主有5台机上网,则需要一个8口路由器,组网方法如下:设备:1、8口路由器一台,其中8口为LAN(局域网)端口,一个WAN(广域网)端口,价格100--400元2、网线N米,这个你自己会看了:)...
- 笔记本电脑各种参数介绍(笔记本电脑各项参数新手普及知识)
-
1、CPU:这个主要取决于频率和二级缓存,频率越高、二级缓存越大,速度越快,现在的CPU有三级缓存、四级缓存等,都影响相应速度。2、内存:内存的存取速度取决于接口、颗粒数量多少与储存大小,一般来说,内...
- 汉字上面带拼音输入法下载(字上面带拼音的输入法是哪个)
-
使用手机上的拼音输入法打成汉字的方法如下:1.打开手机上的拼音输入法,在输入框中输入汉字的拼音,例如“nihao”。2.根据输入法提示的候选词,选择正确的汉字。例如,如果输入“nihao”,输...
- xpsp3安装版系统下载(windowsxpsp3安装教程)
-
xpsp3纯净版在采用微软封装部署技术的基础上,结合作者的实际工作经验,融合了许多实用的功能。它通过一键分区、一键装系统、自动装驱动、一键设定分辨率,一键填IP,一键Ghost备份(恢复)等一系列...
- 没有备份的手机数据怎么恢复
-
手机没有备份恢复数据方法如下1、使用数据线将手机与电脑连接好,在“我的电脑”中可以看到手机的盘符。 2、将手机开启USB调试模式。在手机设置中找到开发者选项,然后点击“开启USB调试模式”。 3、...
- 电脑怎么激活windows11专业版
-
win11专业版激活方法有多种,以下提供两种常用的激活方式:方法一:使用激活密钥激活。在win11桌面上右键点击“此电脑”,选择“属性”选项。进入属性页面后,点击“更改产品密钥或升级windows”。...
- 华为手机助手下载官网(华为手机助手app下载专区)
-
华为手机助手策略调整,已不支持从应用市场下载手机助手,目前华为手机助手是需要在电脑上下载或更新手机助手到最新版本,https://consumer.huawei.com/cn/support/his...
- 光纤线断了怎么接(宽带光纤线断了怎么接)
-
宽带光纤线断了可以重接,具体操作方法如下:1、光纤连接的时候要根据束管内,同色相连,同芯相连,按顺序进行连接,由大到小。一般有三种连接方法,分别是熔接、活动连接和机械连接。2、连接的时候要开剥光缆,抛...
- win7旗舰版和专业版区别(win7旗舰版跟专业版)
-
1、功能区别:Win7旗舰版比专业版多了三个功能,分别是Bitlocker、BitlockerToGo和多语言界面; 2、用途区别:旗舰版的功能是所有版本中最全最强大的,占用的系统资源,...
- 万能连接钥匙(万能wifi连接钥匙下载)
-
1、首先打开wifi万能钥匙软件,若手机没有开启WLAN,就根据软件提示打开WLAN开关;2、打开WLAN开关后,会显示附近的WiFi,如果知道密码,可点击相应WiFi后点击‘输入密码’连接;3、若不...
- 雨林木风音乐叫什么(雨林木风是啥)
-
雨林木风的创始人是陈年鑫先生。陈年鑫先生于1999年创立了雨林木风公司,其初衷是为满足中国市场对高品质、高性能电脑的需求。在陈年鑫先生的领导下,雨林木风以技术创新、产品质量和客户服务为核心价值,不断推...
- aics6序列号永久序列号(aics6破解序列号)
-
关于AICS6这个版本,虽然是比较久远的版本,但是在功能上也是十分全面和强大的,作为一名平面设计师的话,AICS6的现有的功能已经能够应付几乎所有的设计工作了……到底AICC2019的功能是不是...
- 手机可以装电脑系统吗(手机可以装电脑系统吗怎么装)
-
答题公式1:手机可以通过数据线或无线连接的方式给电脑装系统。手机安装系统需要一定的技巧和软件支持,一般需要通过数据线或无线连接的方式与电脑连接,并下载相应的软件和系统文件进行安装。对于大部分手机用户来...
- 一周热门
- 最近发表
- 标签列表
-
- python判断字典是否为空 (50)
- crontab每周一执行 (48)
- aes和des区别 (43)
- bash脚本和shell脚本的区别 (35)
- canvas库 (33)
- dataframe筛选满足条件的行 (35)
- gitlab日志 (33)
- lua xpcall (36)
- blob转json (33)
- python判断是否在列表中 (34)
- python html转pdf (36)
- 安装指定版本npm (37)
- idea搜索jar包内容 (33)
- css鼠标悬停出现隐藏的文字 (34)
- linux nacos启动命令 (33)
- gitlab 日志 (36)
- adb pull (37)
- python判断元素在不在列表里 (34)
- python 字典删除元素 (34)
- vscode切换git分支 (35)
- python bytes转16进制 (35)
- grep前后几行 (34)
- hashmap转list (35)
- c++ 字符串查找 (35)
- mysql刷新权限 (34)
