在使用 cmake 构建的项目中添加头文件和 .cpp 文件

Adding header and .cpp files in a project built with cmake(在使用 cmake 构建的项目中添加头文件和 .cpp 文件)
本文介绍了在使用 cmake 构建的项目中添加头文件和 .cpp 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经使用 cmake 和一些库构建了一个项目.但是我想在我要编写代码的项目中添加一些头文件和 .cpp 文件.最简单的方法是什么?我可以只创建一个 .cpp 文件吗?cpp 和头文件,然后在 Visual Studio 中再次构建项目?或者由于项目是使用 cmake 构建的,我不能?

I have built a project using cmake and some libraries.I want however to add some header and .cpp files in the project which I am going to code.What is the easiest way to do it?Can I just create a .cpp and header files and then build again project in Visual Studio? Or due to the fact that project was built using cmake I can't?

推荐答案

您可以将所有头文件/源文件放在同一个文件夹中并使用类似

You can put all header/source files in the same folder and use something like

file(GLOB SOURCES
    header-folder/*.h
    source-folder/*.cpp
)

add_executable(yourProj ${SOURCES})

这样,您可以通过以下两种方法之一将新添加的 header/source 添加到 VS 中:

In this way, you can do either of the following two methods to add new added header/source into VS:

  1. 需要再次在 CMake 中生成.
  2. 假编辑CMakeLists.txt 一点点,例如只需添加一个空格.然后在 VS 中构建您的解决方案,它会自动添加新的头文件/源文件.
  1. need to generate in CMake again.
  2. fake to edit the CMakeLists.txt a little bit, e.g. simply add a space. And then build your solution in VS, it will automatically add new header/source files.

这篇关于在使用 cmake 构建的项目中添加头文件和 .cpp 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)