百度360必应搜狗淘宝本站头条
当前位置:网站首页 > IT知识 > 正文

visual studio 2022 远程开发:linux+cmake+vcpkg开发环境配置

liuian 2025-01-21 19:29 50 浏览

最近根据项目需求,需要搭建在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下开发环境配置,亲测可以用。

相关推荐

教你把多个视频合并成一个视频的方法

一.情况介绍当你有一个m3u8文件和一个目录,目录中有连续的视频片段,这些片段可以连成一段完整的视频。m3u8文件打开后像这样:m3u8文件,可以理解为播放列表,里面是播放视频片段的顺序。视频片段像这...

零代码编程:用kimichat合并一个文件夹下的多个文件

一个文件夹里面有很多个srt字幕文件,如何借助kimichat来自动批量合并呢?在kimichat对话框中输入提示词:你是一个Python编程专家,完成如下的编程任务:这个文件夹:D:\downloa...

Java APT_java APT 生成代码

JavaAPT(AnnotationProcessingTool)是一种在Java编译阶段处理注解的工具。APT会在编译阶段扫描源代码中的注解,并根据这些注解生成代码、资源文件或其他输出,...

Unit Runtime:一键运行 AI 生成的代码,或许将成为你的复制 + 粘贴神器

在我们构建了UnitMesh架构之后,以及对应的demo之后,便着手于实现UnitMesh架构。于是,我们就继续开始UnitRuntime,以用于直接运行AI生成的代码。PS:...

挣脱臃肿的枷锁:为什么说Vert.x是Java开发者手中的一柄利剑?

如果你是一名Java开发者,那么你的职业生涯几乎无法避开Spring。它如同一位德高望重的老国王,统治着企业级应用开发的大片疆土。SpringBoot的约定大于配置、SpringCloud的微服务...

五年后,谷歌还在全力以赴发展 Kotlin

作者|FredericLardinois译者|Sambodhi策划|Tina自2017年谷歌I/O全球开发者大会上,谷歌首次宣布将Kotlin(JetBrains开发的Ja...

kotlin和java开发哪个好,优缺点对比

Kotlin和Java都是常见的编程语言,它们有各自的优缺点。Kotlin的优点:简洁:Kotlin程序相对于Java程序更简洁,可以减少代码量。安全:Kotlin在类型系统和空值安全...

移动端架构模式全景解析:从MVC到MVVM,如何选择最佳设计方案?

掌握不同架构模式的精髓,是构建可维护、可测试且高效移动应用的关键。在移动应用开发中,选择合适的软件架构模式对项目的可维护性、可测试性和团队协作效率至关重要。随着应用复杂度的增加,一个良好的架构能够帮助...

颜值非常高的XShell替代工具Termora,不一样的使用体验!

Termora是一款面向开发者和运维人员的跨平台SSH终端与文件管理工具,支持Windows、macOS及Linux系统,通过一体化界面简化远程服务器管理流程。其核心定位是解决多平台环境下远程连接、文...

预处理的底层原理和预处理编译运行异常的解决方案

若文章对您有帮助,欢迎关注程序员小迷。助您在编程路上越走越好![Mac-10.7.1LionIntel-based]Q:预处理到底干了什么事情?A:预处理,顾名思义,预先做的处理。源代码中...

为“架构”再建个模:如何用代码描述软件架构?

在架构治理平台ArchGuard中,为了实现对架构的治理,我们需要代码+模型描述所要处理的内容和数据。所以,在ArchGuard中,我们有了代码的模型、依赖的模型、变更的模型等,剩下的两个...

深度解析:Google Gemma 3n —— 移动优先的轻量多模态大模型

2025年6月,Google正式发布了Gemma3n,这是一款能够在2GB内存环境下运行的轻量级多模态大模型。它延续了Gemma家族的开源基因,同时在架构设计上大幅优化,目标是让...

比分网开发技术栈与功能详解_比分网有哪些

一、核心功能模块一个基本的比分网通常包含以下模块:首页/总览实时比分看板:滚动展示所有正在进行的比赛,包含比分、比赛时间、红黄牌等关键信息。热门赛事/焦点战:突出显示重要的、关注度高的比赛。赛事导航...

设计模式之-生成器_一键生成设计

一、【概念定义】——“分步构建复杂对象,隐藏创建细节”生成器模式(BuilderPattern):一种“分步构建型”创建型设计模式,它将一个复杂对象的构建与其表示分离,使得同样的构建过程可以创建...

构建第一个 Kotlin Android 应用_kotlin简介

第一步:安装AndroidStudio(推荐IDE)AndroidStudio是官方推荐的Android开发集成开发环境(IDE),内置对Kotlin的完整支持。1.下载And...