我嘗試爲我的CLion項目運行一些基本命令,但它不起作用。這是我的CMake設置。CMake找不到自定義命令「ls」
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時,我收到以下錯誤消息。
[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命令你好」,看看在完成構建窗口或運行窗口中的結果。
問題CMake的代碼是不是正在構建過程中使用。我認爲你有'命令'ls -l hello「'(引用的命令+參數)。另一種猜測是,也許你在Windows上運行命令,並且%PATH%中沒有「ls」可執行文件。 –
謝謝。它在我的%path%中,但它不適用於CMake。所以我嘗試了完整路徑。 – Leonard