如何配置CMake,以便生成的Visual Studio项目找到可执行文件? [英] How to configure CMake so that the generated Visual Studio project finds the executable?

查看:346
本文介绍了如何配置CMake,以便生成的Visual Studio项目找到可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows上的Visual Studio 2017中使用CMake设置项目. CMakeLists.txt非常简单.我只是在添加带有源文件的可执行文件,然后将链接器语言指定为C ++.

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++.

然后,我在build_64文件夹中运行cmake,并得到包含ALL_BUILD,ZERO_CHECK和我的实际项目的生成的VS解决方案.我将其设置为我的启动项目并尝试运行它,但随后出现此错误消息:

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:

无法启动程序'C:\ Users ... \ Documents \ MyProject \ build_64 \ Debug \ Project1.exe'. 系统找不到指定的文件.

Unable to start program 'C:\Users...\Documents\MyProject\build_64\Debug\Project1.exe'. The system is unable to find the specified file.

CMakeLists.txt:

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命令:

cmake .. -G "Visual Studio 15 2017 Win64"

为什么Visual Studio找不到我的可执行文件?以及如何配置它以便Visual Studio能够找到它?

Why can Visual Studio not find my executable? And how can I configure it so that Visual Studio finds it?

这是我的文件夹结构:

MyProject
   - build_64
       - ALL_BUILD.vcxproj
       ...
       - MyProject.sln
       - Project1.vcxproj
       - ZERO_CHECK.vcxproj
    - Project1
       - src
CMakeLists.txt
CMakeSettings.json

推荐答案

Cmake不会生成可执行文件-cmake为您创建了一个构建系统.然后,您需要在VS或命令行中构建项目. 如果您需要处理一些可执行文件,然后再调用它,那么这里是您的摘录:

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}" )

这篇关于如何配置CMake,以便生成的Visual Studio项目找到可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆