我在 El Capitan 上使用 CLion。现在我需要在我的项目中使用 readline 和 add_history 函数。但链接器提示下面的那些。
Undefined symbols for architecture x86_64:
"_add_history", referenced from:
_main in lisp_3.c.o
"_readline", referenced from:
_main in lisp_3.c.o
ld: symbol(s) not found for architecture x86_64
我可以通过在手动编译时添加 -ledit
标志或在 Xcode 中链接 libedit.tbd 来解决这个问题,但 CLion 使用 CMake。所以我不知道应该将哪个库添加到 CMakeLists.txt 中。
这是我第一次使用CMake来构建项目。而我只能跟随他在这个问题中所做的How to include C static libraries in CMAKE project on MAC OS X
cmake_minimum_required(VERSION 3.3)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(SOURCE_FILES read.c)
add_executable(test ${SOURCE_FILES})
find_library(readline_lib /* what can I place here?*/)
set(frameworks ${readline_lib})
target_link_libraries(test ${frameworks})
最佳答案
readline 库的 tar 链接位于:<https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html>
或更多直接来自:<git.savannah.gnu.org/cgit/readline.git/snapshot/readline-master.tar.gz>
我认为历史函数来自 readline 库。
关于c - 我应该在 CLion 中包含哪个库才能启用 readline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963573/