How to configure CMake so that the generated Visual Studio project finds the executable?

拈花ヽ惹草 提交于 2020-01-24 20:47:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!