CMake找不到自定义命令“ ls”。 [英] CMake does not find custom command "ls"

查看:180
本文介绍了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天全站免登陆