CMake 没有找到自定义命令 "ls" [英] CMake does not find custom command "ls"

查看:43
本文介绍了CMake 没有找到自定义命令 "ls"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为我的 CLion 项目运行一些基本命令,但它不起作用.这是我的 CMake 设置.

I try to run some basic commands for my CLion projects, but it just doesn't work. Here is my CMake setting.

cmake_minimum_required(VERSION 3.6)
project(hello)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(hello ${SOURCE_FILES})

add_custom_command(OUTPUT hello.out
        COMMAND ls -l hello
        DEPENDS hello)

add_custom_target(run_hello_out
        DEPENDS hello.out)

我在 CLion 中运行 run_hello_out 时收到以下错误消息.

I got the following error messages when running run_hello_out in CLion.

[100%] Generating hello.out
process_begin: CreateProcess(NULL, ls -l hello, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make.exe[3]: *** [hello.out] Error 2
mingw32-make.exe[2]: *** [CMakeFiles/run_hello_out.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/run_hello_out.dir/rule] Error 2
mingw32-make.exe: *** [run_hello_out] Error 2
CMakeFiles\run_hello_out.dir\build.make:59: recipe for target 'hello.out' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/run_hello_out.dir/all' failed
CMakeFiles\Makefile2:73: recipe for target 'CMakeFiles/run_hello_out.dir/rule' failed
Makefile:117: recipe for target 'run_hello_out' failed

它应该运行ls -l hello"并在构建窗口或运行窗口中查看结果.

It is supposed to run "ls -l hello" and see the results in either build window or run window.

推荐答案

不知何故,即使我正确设置了全局路径,ls 也不起作用.CMake 需要完整路径.以下工作并解决了问题.

Somehow ls doesn't work even I set up the global path correctly. CMake needs full path. The following works and solves the issue.

add_custom_command(OUTPUT hello.out
        COMMAND "C:\\FULL PATH HERE\\ls" -l hello
        DEPENDS hello)

这篇关于CMake 没有找到自定义命令 "ls"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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