在没有IDE的Windows上使用Cmake
Using cmake on windows without IDE
这可能是重复的,但是我已经花了几个小时来寻找答案...没有解决方案。首先,我知道如果我使用Linux,可能不存在这个问题,但是我在Windows上。
我是C 的新手,但已经对Java和Gradle有了一些经验。我尝试使用cmake,就像我用来使用gradle一样。我已经阅读了Cmake Wiki,但我要么找不到正确的页面,要么我不明白。这是我的目录结构:
MyProject
-bin
-include
--header1.h
--header2.h
--header3.h
--header4.h
--header5.h
--header6.h
-src
--CMakeLists.txt
--MyProjectConfig.h.in
--impl1.cpp
--impl2.cpp
--impl3.cpp
--impl4.cpp
--impl5.cpp
--impl6.cpp
-main.cpp
-CMakeLists.txt
我的项目文件夹中的CMakeLists.txt
看起来像:
cmake_minimum_required (VERSION 3.14)
project (MyProject)
add_subdirectory(src)
file(GLOB_RECURSE sources src/*.cpp include/*.h)
# The version number.
set (Tutorial_VERSION_MAJOR 0)
set (Tutorial_VERSION_MINOR 1)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/MyProjectConfig.h.in"
"${PROJECT_BINARY_DIR}/MyProjectConfig.h"
)
# add the binary tree to the search path for include files
# so that we will find MyProjectConfig.h
include_directories("${PROJECT_BINARY_DIR}")
install (FILES "${PROJECT_BINARY_DIR}/MyProjectConfig.h"
DESTINATION include)
add_executable(MyProject main.cxx ${sources})
# add the install targets
install (TARGETS MyProject DESTINATION bin)
我的cmakelists.txt在src文件夹中看起来像:
cmake_minimum_required (VERSION 3.14)
include_directories(${MyProject_SOURCE_DIR}/MyProject/include)
我在bin bin目录中使用命令: cmake -G "MinGW Makefiles" -S ../src
我现在有2个问题:
- (我如何告诉cmake始终使用mingw?(我不想总是使用-g总是使用))解决
- (编译的文件
buildCMakeFiles3.14.0-rc2CompilerIdCXXa.exe
没有预期的行为。它应该打印" Hello World!"answers"我的类",而"我的类"是从impl1.cpp
创建的类的属性中打印的,但是它无能为力。)需要澄清:如何在控制台上构建Windows .exe-file?
编辑:
我了解到,在创建CMAKE文件后,我必须在BIN目录中调用cmake --build .
。但是,我只是没有得到Exe-File。使用flag -v,我得到此输出:
"C:Program FilesCMakebincmake.exe" -SD:gitMyProjectsrc -BD:gitMyProjectbin --check-build-system CMakeFilesMakefile.cmake 0
"C:Program FilesCMakebincmake.exe" -E cmake_progress_start D:gitMyProjectbinCMakeFiles D:gitMyProjectbinCMakeFilesprogress.marks
C:/MinGW/bin/mingw32-make.exe -f CMakeFilesMakefile2 all
mingw32-make.exe[1]: Entering directory 'D:/git/MyProject/bin'
mingw32-make.exe[1]: Nothing to be done for 'all'.
mingw32-make.exe[1]: Leaving directory 'D:/git/MyProject/bin'
"C:Program FilesCMakebincmake.exe" -E cmake_progress_start D:gitMyProjectbinCMakeFiles 0 ```
- 使用-g选项是这样做的标准方法。它可以防止您不得不将特定于系统的设置放入您的CMAKE配置中(例如MINGW的硬编码路径),并允许您使用其他编译器而不必更改构建脚本。
- 您开始的
a.exe
不是您的构建输出。它应称为MyProjectExec.exe
。另外,您需要将调用中的所有源文件指定为add_executable
。add_subdirectory
不会自动添加任何源文件(应该添加哪个构建输出?),它只是执行cmakelists.txt。
相关文章:
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建
- CMake 在 Windows 上的自定义位置上找不到 Boost
- Cmake with Flex/Bison on windows
- 使用 CMake 在 Windows 10 上构建 uWebSockets
- 在 Windows 10 下使用 GTest 的 CMake - 致命错误 LNK1104:无法打开文件"gtest.lib",但存在调试"gtestd.lib"
- CMake 看不到SDL2_PATH环境变量 (Windows)
- 如何使用cmake和Visual Studio 2019编译简单的Windows应用程序?
- CMake & MinGW Compileilation on Windows,无需 -G "MinGW Makefiles"标志
- OpenCV cmake构建总是在Windows中抛出错误
- 如何在Windows上链接动态构建的cmake文件
- 用于Clang on Windows的CMake生成器
- 在windows上使用cmake编译FFTW(OpenMP)
- CMake Qt建立在Windows链接器问题之上
- CMake 生成的程序无法在 Windows 上链接:尝试链接到不存在的文件
- 如何使用CMake在Windows上将应用程序入口点设置为main()C++?
- 在Windows上设置CMake和vcpkg时出错"无法打开包含文件"
- 简单的cmake项目,在Windows上使用nmake构建没有调试符号
- CMAKE:查找/添加Visual Studio或Windows SDK库和标头的正确方法?
- 需要示例 CMake 项目,该项目在 Windows 和 Visual Studio 上使用 Xerces-C++ 3
- CMake linking Windows SDK