I have been using nana library for a while for my application on Windows and it works great. Now I am trying to do a Linux build but I can not seem to link nana to my application correctly.
I have tried this but it also did not seem to work
I have created a small example to demonstrate the issue. Here is my main.cpp
#include <nana/gui/filebox.hpp>
#include <iostream>
int main()
{
nana::filebox picker{nullptr, true};
auto paths = picker.show();
if(paths.empty())
{
std::cout<<"Cancelled"<<std::endl;
}
else
{
for(auto & p : paths)
std::cout << "Selected file:" << p << std::endl;
}
}
and my CMakeList looks like this:
cmake_minimum_required(VERSION 3.0.0)
project(NanaTest VERSION 0.1.0)
include(CTest)
enable_testing()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall")
#set(CMAKE_LINK_WHAT_YOU_USE TRUE)
add_executable(NanaTest main.cpp)
target_include_directories(NanaTest PRIVATE
usr/local/include/nana)
find_library(NANALIB NAMES libnana.a REQUIRED PATHS usr/local/lib/)
if(NOT NANALIB)
message([FATAL_ERROR] "NANALIB not found")
endif()
target_link_libraries(NanaTest ${NANALIB})
#target_link_libraries(${PROJECT_NAME} -lnana)
target_link_libraries(${PROJECT_NAME} -lX11)
target_link_libraries(${PROJECT_NAME} -lXcursor)
target_link_libraries(${PROJECT_NAME} -lpthread )
target_link_libraries(${PROJECT_NAME} -lXft )
target_link_libraries(${PROJECT_NAME} -lfontconfig )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
This seems to work when I run. However, it does not work when I copy it to another VM. Also the ldd result does not seem to contain libnana.so the shared object. When I run this on the other VM I get segmentation fault and when I run it with gdb this is the error I am getting:
Program received signal SIGSEGV, Segmentation fault.
0x0000555555b80a21 in nana::detail::platform_spec::platform_spec() ()
When I uncomment set(CMAKE_LINK_WHAT_YOU_USE TRUE) and target_link_libraries(${PROJECT_NAME} -lnana)
I can see the libnana.so in ldd result however this time when application ends I get a double free or corruption (!prev) Aborted (core dumped)
error. Does anybody know what the issue could be. I am using GCC 9.3.0. Thank you in advance. By the way I am using nana-hotfix-1.7.4 but I tried 1.7.1, 1.7.2 and 1.7.3 they have the same issue.