简体   繁体   English

如何在 vscode 中设置项目文件夹并链接所有 cpp 文件

[英]how do i set up a project folder in vscode and link all cpp files

i'm new to cpp and just moved to classes, but now im stuck here wondering how do i link 2 or more cpp files to make a project(main.cpp - for main, abc.h - for defining class, abc.cpp- for defining methods outside the class).我是 cpp 的新手,刚开始上课,但现在我想知道如何链接 2 个或多个 cpp 文件来创建项目(main.cpp - 用于 main,abc.h - 用于定义 class,abc.cpp - 用于定义类外的方法)。 For now i use the command g++ main.cpp abc.cpp -o main to link all the files but as my project grows larger it will become more tedious to enter all the file names.Some guy here told if i create a project i should be able to compile as usual without compiling manually.So how do i do that in vscode?现在我使用命令g++ main.cpp abc.cpp -o main链接所有文件,但是随着我的项目变大,输入所有文件名将变得更加乏味。这里有人告诉我如果我创建一个项目,我应该能够像往常一样编译而无需手动编译。那么我如何在 vscode 中做到这一点?

You should look for the concept of makefile, and especially cmake which will help you for your compilation problem.您应该寻找 makefile 的概念,尤其是 cmake,它将帮助您解决编译问题。

For bigger projects you can use makefile for compiling easily and faster.对于更大的项目,您可以使用 makefile 轻松快速地进行编译。 So in vs code I recommend you to use this extension.所以在 vs code 中我推荐你使用这个扩展。 VS Code C/C++ Makefile Project VS Code C/C++ Makefile 项目

Firstly,首先,

C/C++ Make: INIT Project C/C++ 制作:初始化项目

After,后,

C++ Project C++项目

In makefile you can customize your settings.在 makefile 中,您可以自定义设置。

Also you can watch this tutorial video to understand easily this process in vs code Debugging Makefile Project with Visual Studio Code您也可以观看本教程视频,以便在 vs 代码中使用 Visual Studio Code 调试 Makefile 项目轻松理解此过程

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

相关问题 如何将包含几个带有main()定义的.cpp源文件的文件夹导入Eclipse项目? - How do I import a folder with several .cpp source files, each with a main() definition, into an Eclipse project? 如何将文件夹与另一个目录中的某些.cpp和.h文件链接在一起,作为虚幻引擎项目的包含路径? - How to link a folder with some .cpp and .h files in a another directory as a Include path to Unreal Engine Project? 在这种情况下,如何包含所有.cpp和头文件? - How do I include all .cpp and header files in this situation? 试图通过.h和.cpp文件设置类 - 为什么我会收到这些错误? - Trying to set up a class thru .h and .cpp files — why do I get these errors? VSCode 只构建 main.cpp 文件而不是文件夹中的所有文件 - VSCode builds only the main.cpp file instead of all files in the folder VSCode中的Cpp - 如何编译到其他文件夹 - Cpp in VSCode - How to compile to other folder 如何设置scons以构建已生成源文件的项目? - How do I set up scons to build a project that has generated source files? 如何将具有继承的类拆分为不同的.h / .cpp文件? - How do I split classes with inheritance up into different .h/.cpp files? 如何在 VSCode 中链接库? - How do I link a library in VSCode? 如何在 CMake 中设置此文件夹结构? - How do I set up this folder structure in CMake?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM