简体   繁体   English

使用 VS Code 进行跨平台可扩展 C++ 项目

[英]Use VS Code for Cross-Platform Scalable C++ Project

This tutorial provided by the VS Code team explains how to setup C++ in VS Code with MinGW ( https://code.visualstudio.com/docs/cpp/config-mingw ), however it seems to only target small-scale projects as it is configured to rebuilds all files each time, and isn't setup to allow for easy configuration of a project (global defines, adding link libraries etc.) (or am I missing something?). VS Code 团队提供的本教程解释了如何在 VS Code 中使用 MinGW 设置 C++ ( https://code.visualstudio.com/docs/cpp/config-mingw ),但它似乎只针对小型项目配置为每次重建所有文件,并且没有设置为允许轻松配置项目(全局定义,添加链接库等)(或者我错过了什么?)。

I am looking into using CMake as my build tool inside VS Code, however am really turned off by the idea of having to update the CMakeLists.txt file to change my project's configurations, eg every time I add files to my project or link a new library, as I have grown up using IDEs who do this process for me, which I find magnitudes easier as it allows me to purely to focus on writing code.我正在考虑使用 CMake 作为我在 VS Code 中的构建工具,但是我真的被必须更新 CMakeLists.txt 文件以更改我的项目配置的想法关闭了,例如每次我将文件添加到我的项目或链接一个新的库,因为我是使用为我完成这个过程的 IDE 长大的,我发现它更容易,因为它让我可以完全专注于编写代码。

My question is, is there a known method to setup VS Code that will allow me to use a tool such as CMake without having to tinker with it too often?我的问题是,是否有一种已知的方法来设置 VS Code,它允许我使用诸如 CMake 之类的工具,而不必经常修改它?

This tutorial seems like a good starting point to setup CMake, but its method requires CMake knowledge https://pspdfkit.com/blog/2019/visual-studio-code-for-cpp/本教程似乎是设置 CMake 的良好起点,但其方法需要 CMake 知识https://pspdfkit.com/blog/2019/--code

I ideally would like the setup to cater for both small-scale and large-scale projects, both of which should allow for cross-platform building.理想情况下,我希望该设置能够同时满足小型和大型项目的需求,这两者都应该允许跨平台构建。

Thanks谢谢

As Visual Studio Code is not a heavy weight IDE, you will need to put some effort to get it run the way you want it to have, either: Write a CMake InputFile generator, eg :由于 Visual Studio Code 不是重量级的 IDE,因此您需要付出一些努力才能让它按照您希望的方式运行,或者:编写 CMake InputFile 生成器,例如:

list(APPEND EXECUTABLE_LIST executable_1 executable_2)
list(APPEND LIBRARY_LIST library_2 library_2 library_3)

foreach(lib IN LISTS LIBRARY_LIST)
     add_library(${lib} STATIC ${lib}.cpp)
endforeach()

foreach(exe IN LISTS EXECUTABLE_LIST)
    add_executable(${exe} ${exe}.cpp)
    target_include_directories(${exe} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
    target_link_libraries(${exe} ${LIBRARY_LIST})
endforeach()

or you could also use Visual Studio Code CMake Tool extention或者您也可以使用Visual Studio Code CMake 工具扩展

For sure, you couldn't expect the highly functionality like Visual Studio in VS Code as they serve different purpose (highly specialised, deep system couple but slow and big vs small, fast, highly configurable).当然,你不能指望像VS Code中的Visual Studio这样的高功能,因为它们服务于不同的目的(高度专业化、深度系统耦合但速度慢、大vs小、快、高度可配置)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM