Mac 10.13.3上的体系结构x86_64(libdialog.a)的未定义符号

时间:2018-03-13 19:49:18

标签: c++ c cmake

我正在开发一个C ++程序,该程序使用了用C语言编写的对话框库(http://invisible-island.net/dialog/)。我已经能够在Linux上成功编译并链接我的应用程序。关注CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(zerus)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)

find_package(Lua REQUIRED)
find_package(Curses REQUIRED)
find_package(Threads REQUIRED)

add_executable(${PROJECT_NAME} main.cpp headers/Utilities.h source/Utilities.cpp headers/config/lua/LuaConfiguration.h source/config/lua/LuaConfiguration.cpp headers/config/PlatformProcessConfiguration.h source/config/PlatformProcessConfiguration.cpp headers/config/PlatformConfiguration.h source/config/PlatformConfiguration.cpp headers/config/PlatformServiceConfiguration.h source/TmuxSessionManager.cpp headers/TmuxSessionManager.h source/PlatformOvermind.cpp headers/PlatformOvermind.h headers/ProcessStartResult.h headers/dialogs/DialogMainMenu.h source/dialogs/DialogMainMenu.cpp source/dialogs/ModdedDialog.cpp headers/dialogs/ModdedDialog.h source/dialogs/DialogServicesChecklist.cpp headers/dialogs/DialogServicesChecklist.h source/ui/UIManager.cpp headers/ui/UIManager.h headers/dialogs/DialogRegionsChecklist.h source/dialogs/DialogRegionsChecklist.cpp source/dialogs/DialogResolveDependenciesYesNo.cpp headers/dialogs/DialogResolveDependenciesYesNo.h source/dialogs/DialogProcessesChecklist.cpp headers/dialogs/DialogProcessesChecklist.h)

target_link_libraries(${PROJECT_NAME} lua curl dialog Threads::Threads)

但是,当我尝试在Mac上构建相同的项目时,它会编译,但链接器会失败:

Undefined symbols for architecture x86_64:
      "_COLOR_PAIRS", referenced from:
          _dlg_print_text in libdialog.a(util.o)
          _dlg_color_setup in libdialog.a(util.o)
          _dlg_color_pair in libdialog.a(util.o)
      "_COLS", referenced from:
          _dlg_put_backtitle in libdialog.a(util.o)
          _dlg_clear in libdialog.a(util.o)
          _init_dialog in libdialog.a(util.o)
          _dlg_auto_size in libdialog.a(util.o)
          _dlg_auto_sizefile in libdialog.a(util.o)
          _dlg_ctl_size in libdialog.a(util.o)
          _dlg_box_x_ordinate in libdialog.a(util.o)
          ...
      "_LINES", referenced from:
          _dlg_clear in libdialog.a(util.o)
          _init_dialog in libdialog.a(util.o)
          _dlg_print_scrolled in libdialog.a(util.o)
          _dlg_auto_size in libdialog.a(util.o)
          _dlg_auto_sizefile in libdialog.a(util.o)
          _dlg_ctl_size in libdialog.a(util.o)
          _dlg_calc_listh in libdialog.a(util.o)
          ...
      "__nc_wacs", referenced from:
          _dlg_draw_arrows2 in libdialog.a(arrows.o)
          _dlg_draw_scrollbar in libdialog.a(arrows.o)
      "_acs_map", referenced from:
          _dlg_put_backtitle in libdialog.a(util.o)
          _dlg_boxchar in libdialog.a(util.o)
          _dlg_print_scrolled in libdialog.a(util.o)
          _dlg_draw_box2 in libdialog.a(util.o)
          _dlg_asciibox in libdialog.a(util.o)
          _dlg_draw_bottom_box2 in libdialog.a(util.o)
          _dlg_draw_arrows2 in libdialog.a(arrows.o)
          ...
      "_beep", referenced from:
          _dialog_yesno in libdialog.a(yesno.o)
          _dlg_beeping in libdialog.a(util.o)
          _dlg_checklist in libdialog.a(checklist.o)
          _dlg_menu in libdialog.a(menubox.o)
          _dlg_edit_string in libdialog.a(inputstr.o)
          _mouse_wgetch in libdialog.a(mousewget.o)
          _dialog_textbox in libdialog.a(textbox.o)
          ...
         (maybe you meant: _dlg_beeping)
      "_cbreak", referenced from:
          _init_dialog in libdialog.a(util.o)
...etc.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试了几种方法来解决这个问题,包括:

  • 使用extern“C”{}来包含对话框标题(在Linux上没有使用,所有内容都正确链接)。
  • 将构建文件更改为以下内容,以确保CMake正确地找到了库(并且确实如此)。

的CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(zerus)

MESSAGE( STATUS "CMAKE_LIBRARY_PATH: " ${CMAKE_LIBRARY_PATH} )

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)

find_package(Lua REQUIRED)
find_package(Curses REQUIRED)
find_package(Threads REQUIRED)

find_library(DIALOG_LIB dialog)
message(DIALOG_LIB=${DIALOG_LIB})

add_executable(${PROJECT_NAME} <source files>)

target_link_libraries(${PROJECT_NAME} ${DIALOG_LIB} lua curl Threads::Threads)

CMake构建期间的输出验证它正在找到库:

DIALOG_LIB=/usr/local/lib/libdialog.a
  • 验证在Mac上使用make / make install-full创建的静态库是否具有正确的体系结构:

lipo -info /usr/local/lib/libdialog.a

input file /usr/local/lib/libdialog.a is not a fat file

Non-fat file: /usr/local/lib/libdialog.a is architecture: x86_64

  • 验证静态库中的目标文件是否与架构匹配

我不知道从哪里开始。我知道链接器找不到符号,但似乎找到了包含这些符号的库。这是否与Mac上的工具链有关,如果是,它如何修复?

0 个答案:

没有答案