問題描述
我已經使用 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:
- 需要再次在 CMake 中生成.
- 假編輯
CMakeLists.txt
一點點,例如只需添加一個空格.然后在 VS 中構建您的解決方案,它會自動添加新的頭文件/源文件.
- need to generate in CMake again.
- 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 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!