使用DSENT建模NoC功耗与面积时make编译报错求助
解决DSENT编译时python-config相关链接错误
我在/ext/dsent目录下使用DSENT为自研NoC建模功耗与面积,cmake执行正常,但执行make命令时出现如下错误:
Consolidate compiler generated dependencies of target dsent [ 1%] Building CXX object CMakeFiles/dsent.dir/DSENT.cc.o c++: warning: /bin/sh:: linker input file unused because linking not done c++: error: /bin/sh:: linker input file not found: No such file or directory c++: warning: 1:: linker input file unused because linking not done c++: error: 1:: linker input file not found: No such file or directory c++: warning: python-config:: linker input file unused because linking not done c++: error: python-config:: linker input file not found: No such file or directory c++: warning: not: linker input file unused because linking not done c++: error: not: linker input file not found: No such file or directory c++: warning: found: linker input file unused because linking not done c++: error: found: linker input file not found: No such file or directory make[2]: *** [CMakeFiles/dsent.dir/build.make:76: CMakeFiles/dsent.dir/DSENT.cc.o] Error 1 make[2]: *** Deleting file 'CMakeFiles/dsent.dir/DSENT.cc.o' make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/dsent.dir/all] Error 2 make: *** [Makefile:91: all] Error 2
原始CMakeLists.txt内容如下:
cmake_minimum_required (VERSION 2.6) project (DSENT) # find out all the file that need to be compiled file(GLOB_RECURSE SRCS "*.h" "*.cc") # add the library add_library(dsent MODULE ${SRCS}) SET(PYTHON_CONFIG "python-config") # add the binary tree to the search path for include files include_directories("${CMAKE_SOURCE_DIR}" "`${PYTHON_CONFIG} --includes`") EXEC_PROGRAM(${PYTHON_CONFIG} ARGS --cflags OUTPUT_VARIABLE PYTHON_CFLAGS) EXEC_PROGRAM(${PYTHON_CONFIG} ARGS --ldflags OUTPUT_VARIABLE PYTHON_LFLAGS) set_target_properties(dsent PROPERTIES PREFIX "" COMPILE_FLAGS "${PYTHON_CFLAGS} -std=c++11 " LINK_FLAGS "${PYTHON_LFLAGS}")
问题根源
CMakeLists.txt中include_directories行错误地用反引号`包裹${PYTHON_CONFIG} --includes,导致CMake将整个字符串视为文件路径,而非执行命令获取输出;同时老旧的EXEC_PROGRAM命令在新CMake版本中兼容性较差,进一步引发编译参数解析错误。
修复方案
修改CMakeLists.txt,改用execute_process命令正确获取Python相关参数,去除反引号包裹:
cmake_minimum_required (VERSION 2.6) project (DSENT) # 查找所有需要编译的文件 file(GLOB_RECURSE SRCS "*.h" "*.cc") # 添加库 add_library(dsent MODULE ${SRCS}) # 根据系统Python版本调整,比如用python3-config SET(PYTHON_CONFIG "python-config") # 获取Python include路径 execute_process( COMMAND ${PYTHON_CONFIG} --includes OUTPUT_VARIABLE PYTHON_INCLUDES OUTPUT_STRIP_TRAILING_WHITESPACE ) # 获取Python编译参数 execute_process( COMMAND ${PYTHON_CONFIG} --cflags OUTPUT_VARIABLE PYTHON_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ) # 获取Python链接参数 execute_process( COMMAND ${PYTHON_CONFIG} --ldflags OUTPUT_VARIABLE PYTHON_LFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ) # 添加头文件搜索路径 include_directories("${CMAKE_SOURCE_DIR}" ${PYTHON_INCLUDES}) set_target_properties(dsent PROPERTIES PREFIX "" COMPILE_FLAGS "${PYTHON_CFLAGS} -std=c++11" LINK_FLAGS "${PYTHON_LFLAGS}")
后续操作
- 如果系统存在多版本Python,将
PYTHON_CONFIG改为对应版本的config命令(如python3-config) - 重新执行
cmake .生成新的Makefile - 执行
make完成编译
内容的提问来源于stack exchange,提问作者WITHER
相关产品推荐
相关产品推荐

