I'm working on a C++ program which makes use of the dialog library (http://invisible-island.net/dialog/), which is written in C. I've been able to successfully compile and link my application against it on Linux with the following 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)
However, when I try to build the same project on Mac, it compiles but the linker fails with:
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)
I've tried several approaches to fix this including:
- using extern "C" {} to include the dialog header (didn't use on Linux and everything linked correctly).
- Changing build file to the following to ensure that CMake was finding the library correctly (and it was).
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)
Output during CMake's build verified that it was finding the library:
DIALOG_LIB=/usr/local/lib/libdialog.a
- Verifying that the static library created using make/make install-full on the Mac was for the correct architecture:
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
- Verifying that the object files inside the static library matched the architecture
I'm not sure where to go from here. I get that the linker can't find the symbols, but it seems to be finding the library which includes those symbols. Is this related to the toolchain on Mac and if so, how can it be fixed?