CMake编译生成Debug和Release 可执行文件exe

it2024-10-05  40

转自https://blog.csdn.net/u014426939/article/details/80080635

CMake官方说明文档:https://cmake.org/cmake/help/latest/

根据以下步骤,也可实现建立opencv的工程,只需要在Where is the source code:目录为opencv \ sources,该目录下有CMakeList.txt文件

可用命令行方式 cmake [路径] -G “Visual Studio 14 2015 Win64”

也可用cmake-gui

实现编译c、cpp文件,生成.exe文件

1.CMake

按自己电脑配置下载CMake:https://cmake.org/download/

解压得到如图:(还需要配置系统环境变量,…cmake-3.11.1-win64-x64\bin,具体按自己路径配置,为了能在命令行中调用cmake的命令)

在bin文件夹下打开cmake-gui.exe或者直接cmd命令下输入cmake-gui(已配置系统环境变量情况下)

2.工程文件

两个文件放在一个文件夹下,文件名自己命名,我命名为test_cmake

cmake生成需要CMakeLists.txt

cmake_minimum_required (VERSION 2.8) PROJECT (HELLO) #SET(SRC_LIST main.c) #MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR}) #MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR}) ADD_EXECUTABLE(HELLO main.c)

需要编译的main.c文件

#include <stdio.h> int main() { printf("Hello World from t1 Main!\n"); return 0; }

3.配置Cmake

我的工程:

source code:F:/test_cmake

build the binaries:F:/test_cmake/Build

依次点Configure 我选择了用vs2013,Configuring done之后,点Generate,Generating done后,在test_cmake\Build下

3.编译生成.exe

在cmd命令窗口线下,按照cmake [optional] [dir]

输入cmake --build .\Build

最后在Build\Debug下产生.exe文件,默认Debug

若要产生Release ,则使用参照https://cmake.org/cmake/help/latest/manual/cmake.1.html

使用:cmake --build ./Build --config Release

最新回复(0)