[英]How to configure CMake so that the generated Visual Studio project finds the executable?
I'm trying to set up a project with CMake in Visual Studio 2017 on Windows. 我正试图在Windows上的Visual Studio 2017中使用CMake建立一个项目。 The CMakeLists.txt is pretty simple.
CMakeLists.txt非常简单。 I am just adding an executable with source files and I specify the linker language to C++.
我只是添加一个带有源文件的可执行文件,我指定了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. 然后我在build_64文件夹中运行cmake,然后我得到包含ALL_BUILD,ZERO_CHECK和我的实际项目的生成的VS解决方案。 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'. 无法启动程序'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 command: cmake命令:
cmake .. -G "Visual Studio 15 2017 Win64"
Why can Visual Studio not find my executable? 为什么Visual Studio找不到我的可执行文件? And how can I configure it so that Visual Studio finds it?
我如何配置它以便Visual Studio找到它?
Here is my folder structure: 这是我的文件夹结构:
MyProject
- build_64
- ALL_BUILD.vcxproj
...
- MyProject.sln
- Project1.vcxproj
- ZERO_CHECK.vcxproj
- Project1
- src
CMakeLists.txt
CMakeSettings.json
Cmake does not generate executable - cmake creates a build system for you. Cmake不会生成可执行文件--cmake会为您创建一个构建系统。 Then you need to build your project in VS or inside the command line.
然后,您需要在VS或命令行内部构建项目。 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}" )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.