ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.73k stars 401 forks source link

Error when incorporating ftxui into a shared library #759

Closed Maurizio1 closed 10 months ago

Maurizio1 commented 11 months ago

Hi and thanks for this useful library!

I have included ftxui in a class of mine that implements some other output utilities. Class name is 'output'.

No problem when making a static library. When I try to make the 'output' class as a shared library I get the following linker errors:

:-1: error: /usr/local/lib/libftxui-component.a(event.cpp.o): warning: relocation against_ZN5ftxui5Event3F12E' in read-only section .text'

and

:-1: error: /usr/local/lib/libftxui-component.a(catch_event.cpp.o): relocation R_X86_64_PC32 against symbol_ZZNSt19_Sp_make_shared_tag5_S_tiEvE5__tag' can not be used when making a shared object; recompile with -fPIC`

I am compiling with g++ (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0.

Is this a supposed behaviour, am I doing something wrong or it's a bug?

Thanks in advance.

ArthurSonzogni commented 11 months ago

Hi @Maurizio1 Could you please provide the reproduction steps? A minimal example, or giving a link to your github repo for instance.

I feel you installed FTXUI and you might be using g++ manually. Did you considered using CMake to get it right all the time?

find_package(ftxui REQUIRED)
target_link_libraries(mine PRIVATE ftxui::component)
target_link_libraries(mine PRIVATE ftxui::dom)
target_link_libraries(mine PRIVATE ftxui::screen)
Maurizio1 commented 11 months ago

Thanks @ArthurSonzogni

It was my mistake then. (by the way I forgot to mention that I was using Qt Creator and Qmake)

Now I have implemented your suggestion and created a Cmake project with the following CMakeLists.txt (still in Qt Creator):

`cmake_minimum_required(VERSION 3.5)

project(ftxui_cmake_test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(${CMAKE_SOURCE_DIR}/../libraries/dynamic_output_lib) link_directories(${CMAKE_SOURCE_DIR}/../libraries/dynamic_output_lib/build/linux)

add_executable(ftxui_cmake_test main.cpp) target_link_libraries(ftxui_cmake_test PRIVATE dynamic_output_lib)

find_package(ftxui REQUIRED) target_link_libraries(ftxui_cmake_test PRIVATE ftxui::component) target_link_libraries(ftxui_cmake_test PRIVATE ftxui::dom) target_link_libraries(ftxui_cmake_test PRIVATE ftxui::screen)

include(GNUInstallDirs) install(TARGETS ftxui_cmake_test LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )`

Everything works as expected now.

Thank you very much!

ArthurSonzogni commented 10 months ago

Thanks! I guess this is now fixed!