【问题标题】:Which library should I include in CLion to enable readline我应该在 CLion 中包含哪个库以启用 readline
【发布时间】:2016-01-23 12:40:19
【问题描述】:

我在 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

我可以通过在手动编译或在 Xcode 中链接 libedit.tbd 时添加 -ledit 标志来解决它,但 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})

【问题讨论】:

标签: c cmake readline


【解决方案1】:

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 库提供的。

【讨论】:

    【解决方案2】:

    将此行添加到您的 CMakeLists.txt:

    target_link_libraries(yourprojectname /usr/lib/x86_64-linux-gnu/libreadline.so)
    

    【讨论】:

      【解决方案3】:

      我使用以下方法解决了同样的问题:

      target_link_libraries(test edit)
      

      你需要你的程序 test 链接到 editline lib not readline

      下面是编译它的最小CMakeList.txt 文件

      cmake_minimum_required(VERSION 3.3)
      
      project(test C)
      
      set(SOURCE_FILES read.c)
      
      add_executable(test ${SOURCE_FILES})
      
      target_link_libraries(test edit)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-02-28
        • 2016-08-04
        • 1970-01-01
        • 2011-05-06
        • 1970-01-01
        • 2021-07-06
        • 2010-10-30
        • 1970-01-01
        相关资源
        最近更新 更多