问题
I'm trying to set up a project with CMake in Visual Studio 2017 on Windows. The CMakeLists.txt is pretty simple. I am just adding an executable with source files and I specify the linker language to C++.
Then I run cmake in my build_64 folder and I get the generated VS solution containing ALL_BUILD, ZERO_CHECK and my actual project of course. I set it to be my start project and try to run it but then I get this error message:
Unable to start program 'C:\Users...\Documents\MyProject\build_64\Debug\Project1.exe'. The system is unable to find the specified file.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(MyProject)
# create Project1
set(PROJECT1_SOURCES ${CMAKE_SOURCE_DIR}/Project1/src/)
add_executable(Project1 ${PROJECT1_SOURCES})
set_target_properties(Project1 PROPERTIES LINKER_LANGUAGE CXX)
cmake command:
cmake .. -G "Visual Studio 15 2017 Win64"
Why can Visual Studio not find my executable? And how can I configure it so that Visual Studio finds it?
Here is my folder structure:
MyProject
- build_64
- ALL_BUILD.vcxproj
...
- MyProject.sln
- Project1.vcxproj
- ZERO_CHECK.vcxproj
- Project1
- src
CMakeLists.txt
CMakeSettings.json
回答1:
Cmake does not generate executable - cmake creates a build system for you. Then you need to build your project in VS or inside the command line. If you need to address some executable and later call it here is a snippet for you :
find_program(THRIFT_COMPILER NAMES thrift thrift.exe HINTS ${THRIFT_COMPILER_ROOT} ${THRIFT_ROOT}/compiler/cpp/bin ${THRIFT_ROOT}/bin ${THRIFT_ROOT}/bin/Release /usr/local /opt/local PATH_SUFFIXES bin bin64)
exec_program(${THRIFT_COMPILER}
ARGS -version
OUTPUT_VARIABLE __thrift_OUT
RETURN_VALUE THRIFT_RETURN)
message( STATUS "Thrift compiler version: ${__thrift_OUT}" )
来源:https://stackoverflow.com/questions/55418401/how-to-configure-cmake-so-that-the-generated-visual-studio-project-finds-the-exe