-1
我從CMakeLists.txt調用Makefile。 CMakeLists.txt編譯一個打印「Hello world」的main.cpp文件,並調用Makefile。 Makefile編譯一個打印「Test」的test.cpp文件。代碼很好。當我使用Makefile創建test.cpp時,我檢查了它。CMake和Makefile:分段錯誤
問題是當我試圖構建CMakeLists.txt時。 「主」輸出正常工作,但「測試」輸出引發異常:
「段錯誤(核心轉儲)」。
這裏是Makefile文件代碼:
all:
g++ -shared -fPIC -o test test.cpp
這裏是的CMakeLists.txt代碼:
cmake_minimum_required(VERSION 3.5)
project(Call_Makefile_From_CMake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(FullPath "/home/orz/ClionProjects/Call_Makefile_From_CMake")
add_custom_command(
OUTPUT ${FullPath}/Test/test
COMMAND make -f test.mk
WORKING_DIRECTORY ${FullPath}/Test
)
add_custom_target(
extern_lib
DEPENDS ${FullPath}/Test/test
)
add_executable(Call_Makefile_From_CMake main.cpp)
target_link_libraries(Call_Makefile_From_CMake ${FullPath}/Test/test)
add_dependencies(Call_Makefile_From_CMake extern_lib)
感謝對傭工。