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

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

bigegpt 2025-01-18 17:30 3 浏览

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

相关推荐

10w qps缓存数据库——Redis(redis缓存调优)

一、Redis数据库介绍:Redis:非关系型缓存数据库nosql:非关系型数据库没有表,没有表与表之间的关系,更不存在外键存储数据的形式为key:values的形式c语言写的服务(监听端口),用来存...

Redis系列专题4--Redis配置参数详解

本文基于windowsX64,3.2.100版本讲解,不同版本默认配置参数不同在Redis中,Redis的根目录中有一个配置文件(redis.conf,windows下为redis.windows....

开源一夏 | 23 张图,4500 字从入门到精通解释 Redis

redis是目前出场率最高的NoSQL数据库,同时也是一个开源的数据结构存储系统,在缓存、数据库、消息处理等场景使用的非常多,本文瑞哥就带着大家用一篇文章入门这个强大的开源数据库——Redis。...

redis的简单与集群搭建(redis建立集群)

Redis是什么?是开源免费用c语言编写的单线程高性能的(key-value形式)内存数据库,基于内存运行并支持持久化的nosql数据库作用主要用来做缓存,单不仅仅是做缓存,比如:redis的计数器生...

推荐几个好用Redis图形化客户端工具

RedisPlushttps://gitee.com/MaxBill/RedisPlusRedisPlus是为Redis可视化管理开发的一款开源免费的桌面客户端软件,支持Windows、Linux...

关于Redis在windows上运行及fork函数问题

Redis在将数据库进行持久化操作时,需要fork一个进程,但是windows并不支持fork,导致在持久化操作期间,Redis必须阻塞所有的客户端直至持久化操作完成。微软的一些工程师花费时间在解决在...

你必须懂的Redis十大应用场景(redis常见应用场景)

Redis作为一款高性能的键值存储数据库,在互联网业务中有着广泛的应用。今天,我们就来详细盘点一下Redis的十大常用业务场景,并附上Golang的示例代码和简图,帮助大家更好地理解和应用Redis。...

极简Redis配置(redis的配置)

一、概述Redis的配置文件位于Redis安装目录下,文件名为redis.conf(Windows名为redis.windows.conf,linux下的是redis.conf)你可以通过C...

什么是redis,怎么启动及如何压测

从今天起咱们一起来学习一下关于“redis监控与调优”的内容。一、Redis介绍Redis是一种高级key-value数据库。它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富。...

一款全新Redis UI可视化管理工具,支持WebUI和桌面——P3X Redis UI

介绍P3XRedisUI这是一个非常实用的RedisGUI,提供响应式WebUI访问或作为桌面应用程序使用,桌面端是跨平台的,而且完美支持中文界面。Githubhttps://github....

windows系统的服务器快速部署java项目环境地址

1、mysql:https://dev.mysql.com/downloads/mysql/(msi安装包)2、redis:https://github.com/tporadowski/redis/r...

window11 下 redis 下载与安装(windows安装redis客户端)

#热爱编程是一种怎样的体验#window11下redis下载与安装1)各个版本redis下载(windows)https://github.com/MicrosoftArchive/r...

一款轻量级的Redis客户端工具,贼好用!

使用命令行来操作Redis是一件非常麻烦的事情,我们一般会选用客户端工具来操作Redis。今天给大家分享一款好用的Redis客户端工具TinyRDM,它的界面清新又优雅,希望对大家有所帮助!简介Ti...

一个.NET开发且功能强大的Windows远程控制系统

我们致力于探索、分享和推荐最新的实用技术栈、开源项目、框架和实用工具。每天都有新鲜的开源资讯等待你的发现!项目介绍SiMayRemoteMonitorOS是一个基于Windows的远程控制系统,完...

Redis客户端工具详解(4款主流工具)

大家好,我是mikechen。Redis是大型架构的基石,也是大厂最爱考察内容,今天就给大家重点详解4款Redis工具@mikechen本篇已收于mikechen原创超30万字《阿里架构师进阶专题合集...