jupyter-xeus / cpp-terminal

C++ library for writing multiplatform terminal applications
https://jupyter-xeus.github.io/cpp-terminal/
Other
523 stars 55 forks source link

Error linking with CMake #364

Closed Algebro7 closed 4 months ago

Algebro7 commented 4 months ago

The current master branch does not appear to link correctly out of the box on CMake. I'm getting the following error:

[343/376] Linking CXX executable tests
FAILED: tests tests[1]_tests.cmake [...] -o tests  lib/libgtest_main.a  lib/libgmock_main.a  include/fmt/libfmtd.a  include/uvw/src/libuvw.a  _deps/libuv-build/libuv.a  include/libpqxx/src/libpqxx-7.7.a  _deps/sodium-build/libsodium.a  include/spdlog/libspdlogd.a  include/cpp-terminal/cpp-terminal/libcpp-terminal.a  /usr/lib/liblua5.4.so  -lm  lib/libgmock.a  lib/libgtest.a  -lpthread  -ldl  -lrt  /usr/lib/libpq.so  include/fmt/libfmtd.a  include/cpp-terminal/cpp-terminal/private/libcpp-terminal-private.a  /usr/lib/libinih.so  /usr/lib/libINIReader.so && cd /home/algebro/Documents/project/cmake-build-debug && /home/algebro/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/bin/cmake -D TEST_TARGET=tests -D TEST_EXECUTABLE=/home/algebro/Documents/project/cmake-build-debug/tests -D TEST_EXECUTOR= -D TEST_WORKING_DIR=/home/algebro/Documents/project/cmake-build-debug -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_FILTER= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=tests_TESTS -D CTEST_FILE=/home/algebro/Documents/project/cmake-build-debug/tests[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -D TEST_XML_OUTPUT_DIR= -P /home/algebro/.local/share/JetBrains/Toolbox/apps/clion/bin/cmake/linux/x64/share/cmake-3.28/Modules/GoogleTestAddTests.cmake
/usr/bin/ld: include/cpp-terminal/cpp-terminal/private/libcpp-terminal-private.a(terminfo.cpp.o): in function `Term::Terminfo::checkUTF8()':
/home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/terminfo.cpp:178:(.text+0x9df): undefined reference to `Term::Cursor::column() const'
/usr/bin/ld: /home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/terminfo.cpp:178:(.text+0x9ee): undefined reference to `Term::Cursor::column() const'
/usr/bin/ld: include/cpp-terminal/cpp-terminal/private/libcpp-terminal-private.a(cursor.cpp.o): in function `Term::cursor_position()':
/home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/cursor.cpp:54:(.text+0x253): undefined reference to `Term::cursor_position_report[abi:cxx11]()'
/usr/bin/ld: /home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/cursor.cpp:64:(.text+0x49d): undefined reference to `Term::Cursor::Cursor(unsigned long const&, unsigned long const&)'
collect2: error: ld returned 1 exit status
[345/376] Linking CXX executable project
FAILED: project 
: && /usr/bin/c++ -g  [...] -o project  include/fmt/libfmtd.a  include/uvw/src/libuvw.a  _deps/libuv-build/libuv.a  include/libpqxx/src/libpqxx-7.7.a  _deps/sodium-build/libsodium.a  include/spdlog/libspdlogd.a  include/cpp-terminal/cpp-terminal/libcpp-terminal.a  /usr/lib/liblua5.4.so  -lm  -lpthread  -ldl  -lrt  /usr/lib/libpq.so  include/fmt/libfmtd.a  include/cpp-terminal/cpp-terminal/private/libcpp-terminal-private.a  /usr/lib/libinih.so  /usr/lib/libINIReader.so && :
/usr/bin/ld: include/cpp-terminal/cpp-terminal/private/libcpp-terminal-private.a(terminfo.cpp.o): in function `Term::Terminfo::checkUTF8()':
/home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/terminfo.cpp:178:(.text+0x9df): undefined reference to `Term::Cursor::column() const'
/usr/bin/ld: /home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/terminfo.cpp:178:(.text+0x9ee): undefined reference to `Term::Cursor::column() const'
/usr/bin/ld: include/cpp-terminal/cpp-terminal/private/libcpp-terminal-private.a(cursor.cpp.o): in function `Term::cursor_position()':
/home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/cursor.cpp:54:(.text+0x253): undefined reference to `Term::cursor_position_report[abi:cxx11]()'
/usr/bin/ld: /home/algebro/Documents/project/include/cpp-terminal/cpp-terminal/private/cursor.cpp:64:(.text+0x49d): undefined reference to `Term::Cursor::Cursor(unsigned long const&, unsigned long const&)'
collect2: error: ld returned 1 exit status

In this case, I'm adding cpp-terminal to my project like this:

set(CPPTERMINAL_BUILD_EXAMPLES OFF)
set(CPPTERMINAL_ENABLE_INSTALL OFF)
set(CPPTERMINAL_ENABLE_TESTING OFF)
set(CPPTERMINAL_ENABLE_DOCS OFF)
add_subdirectory(include/cpp-terminal)
[...]
target_link_libraries(tests [...] cpp-terminal)
target_link_libraries(project [...] cpp-terminal)

Is there some other target exported by cpp-terminal that I should be linking to?

Thanks!

flagarde commented 4 months ago

Hi,

How are you populating the include/cpp-terminal ?

Algebro7 commented 4 months ago

As a git submodule, so essentially cd include && git clone --recursive https://github.com/jupyter-xeus/cpp-terminal but via git submodule add

flagarde commented 4 months ago

Strange could you send more information on your system and cmake version etc...

I guess cmake doesn't find the private .a library but I don't know why yet.. Are you allowed to send your code or some smaller example of crashing configuration

Algebro7 commented 4 months ago

Here is a minimal example that is showing the same behavior: https://github.com/Algebro7/cpp-terminal-test

The system is Arch Linux with CMake 3.29.6, have tried both clang and gcc. I just tested with the ubuntu:latest Docker container and it's failing with the same error there as well.

flagarde commented 4 months ago

I found the problem, I will push a fix. It's a egg-chicken problem cpp-terminal depends on cpp-terminal-private that depends itself on cpp-terminal. Don't know why in this case the linker i not able to link

flagarde commented 4 months ago

Please check now. Maybe I need to fnd a better way but I like the clear separation between platform dependent code and cross-platform one

Algebro7 commented 4 months ago

That worked, thanks!

flagarde commented 4 months ago

That worked, thanks!

Thx for the news and your time for the minimal example