に一致する場合、私は、次の条件が満たさCMakeので迷惑なエラーに遭遇しています実行可能ファイルとしてディレクトリをリンクしようとCMakeの:それらの名前が
- ターゲット名は、ターゲットを定義するディレクトリの名前と同じです。
- ターゲットに
RUNTIME_OUTPUT_DIRECTORY
プロパティを使用しています。これらの条件の下で
、私はエラーを取得:
Linking CXX executable .
/usr/bin/ld: cannot open output file .: Is a directory
CMakeのは明らかを参照しようとすると、.
という名前のターゲットを構築しようとしているように見えます目的のターゲット名ではなく現在のディレクトリ名。
これは簡単な例です。マイファイルツリーは、次のとおりです。
/tmp/example$ tree
.
├── build
└── src
├── CMakeLists.txt
└── hello_world
├── CMakeLists.txt
└── HelloWorld.cpp
のsrc/CMakeLists.txt:
set (ARBITRARY_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(hello_world)
のsrc/hello_world:
add_executable(hello_world HelloWorld.cpp)
set_property(TARGET hello_world PROPERTY RUNTIME_OUTPUT_DIRECTORY ${ARBITRARY_OUTPUT_DIR})
...とHelloWorld.cpp
自体はで、些細なHello Worldのプログラムですmain()
方法。
私が実行します。
/tmp/example/build$ cmake ../src/ -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8 -G"Unix Makefiles"
/tmp/example/build$ make VERBOSE=1
をそして私が手:
[ 50%] Building CXX object hello_world/CMakeFiles/hello_world.dir/HelloWorld.o
cd /tmp/example/build/hello_world && /usr/bin/g++-4.8 -O3 -DNDEBUG -o CMakeFiles/hello_world.dir/HelloWorld.o -c /tmp/example/src/hello_world/HelloWorld.cpp
[100%] Linking CXX executable .
cd /tmp/example/build/hello_world && /usr/bin/cmake -E cmake_link_script CMakeFiles/hello_world.dir/link.txt --verbose=1
/usr/bin/g++-4.8 -O3 -DNDEBUG CMakeFiles/hello_world.dir/HelloWorld.o -o . -rdynamic
/usr/bin/ld: cannot open output file .: Is a directory
collect2: error: ld returned 1 exit status
あなたが見ることができるように、CMakeFiles/hello_world.dir/link.txt
は明らかに動作しません-o .
、などのリンクターゲットを設定します。
これはCMakeのバグですか、何か間違っていますか?これにはいくつかの回避策がありますか?
私のツールは、次のとおりです。
- cmakeのバージョン3.5.1
- のUbuntu 16.04 LTS(Xenial Xerus)
- グラム++ - 4.8
ARRRG。私はそれを考えなかった。ありがとう:D – Ziv