ggerganov / imtui

ImTui: Immediate Mode Text-based User Interface C++ Library
https://imtui.ggerganov.com
MIT License
2.94k stars 123 forks source link

Linking problem with ImTui #35

Closed SeveriSuominen closed 2 years ago

SeveriSuominen commented 2 years ago

Hello,

I am currently trying to include ImTui to my current console project. I followed instructions and it seems there is some linking problems (probably trivial, I am not too familiar with c/c++ world). I am using CMake and linked all ImTui .a files, I also have ncurses linked to my project. Result when I try to build and run my project:

/usr/bin/ld: /home/shardine/projects/neonlit/client/../lib/libimtui-ncurses.a(imtui-impl-ncurses.cpp.o): in function `ImTui_ImplNcurses_Init(bool, float, float)':
imtui-impl-ncurses.cpp:(.text+0xd2): undefined reference to `initscr'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xd7): undefined reference to `use_default_colors'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xdc): undefined reference to `start_color'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xe1): undefined reference to `cbreak'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xe6): undefined reference to `noecho'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xed): undefined reference to `curs_set'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xf4): undefined reference to `stdscr'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0xfe): undefined reference to `nodelay'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x105): undefined reference to `stdscr'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x10c): undefined reference to `wtimeout'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x116): undefined reference to `set_escdelay'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x11d): undefined reference to `stdscr'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x127): undefined reference to `keypad'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x25b): undefined reference to `stdscr'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x313): undefined reference to `mouseinterval'
/usr/bin/ld: imtui-impl-ncurses.cpp:(.text+0x31f): undefined reference to `mousemask'

so all the link problems seems to be with ncurses. Do you know what I am doing wrong here?

Best regards.

ggerganov commented 2 years ago

Definitely looks like ncurses is not linking properly, but not sure I can help without knowing the build process that you use.

Since you are already using CMake, I recommend adding ImTui as a git submodule to your project and adjusting you CMakeLists.txt to link the imtui target. The hnterm project demonstrates how to do it.

SeveriSuominen commented 2 years ago

@ggerganov thank you for reply. I just got it working. I am just not sure how. So basically only change I made was I moved all the ncurses 'target_link_libraries' calls after ImTui 'target_link_libraries' calls in my CMakeLists.txt, so:

Not working order:

# ncurse before
target_link_libraries(NL_Client libform.a)
target_link_libraries(NL_Client libmenu.a)
target_link_libraries(NL_Client libncurses.a)
target_link_libraries(NL_Client libpanel.a)

# ImTui after
target_link_libraries(NL_Client libimtui-ncurses.a)
target_link_libraries(NL_Client libimtui.a)

And working order:

#ImTui before
target_link_libraries(NL_Client libimtui-ncurses.a)
target_link_libraries(NL_Client libimtui.a)

# ncurse after
target_link_libraries(NL_Client libform.a)
target_link_libraries(NL_Client libmenu.a)
target_link_libraries(NL_Client libncurses.a)
target_link_libraries(NL_Client libpanel.a)

not really sure what happens here.

ggerganov commented 2 years ago

Yeah, sometimes the link order matters - https://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter