saleyn / eixx

Erlang C++ Interface
Apache License 2.0
137 stars 26 forks source link

Error while linking `basic_otp_node_local` #51

Closed heri16 closed 3 years ago

heri16 commented 3 years ago

Error while linking basic_otp_node_local:

[100%] Linking CXX executable 
Undefined symbols for architecture x86_64:
  "eixx::connect::basic_otp_node_local::basic_otp_node_local(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      eixx::connect::basic_otp_node<std::__1::allocator<char>, std::__1::recursive_mutex>::basic_otp_node(boost::asio::io_context&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::allocator<char> const&, signed char) in matching_node.cpp.o
ld: symbol(s) not found for architecture x86_64

CMakefile:

# PkgConfig
find_package(Boost 1.55.0 REQUIRED COMPONENTS system thread)
find_package(PkgConfig REQUIRED)
pkg_search_module(EIXX REQUIRED eixx>=1.4)
pkg_search_module(OPENSSL REQUIRED openssl)
if(Boost_FOUND)
  #include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
  link_directories(${Boost_LIBRARY_DIRS})
  message(STATUS "Found boost: ${Boost_LIBRARY_DIRS}")
endif()
if(EIXX_FOUND)
  #include_directories(SYSTEM ${EIXX_INCLUDE_DIRS})
  link_directories(${EIXX_LIBRARY_DIRS})
  message(STATUS "Found eixx: ${EIXX_LIBRARY_DIRS} ${EIXX_LIBRARIES}")
endif()
if(OPENSSL_FOUND)
  #include_directories(SYSTEM ${OPENSSL_INCLUDE_DIRS})
  link_directories(${OPENSSL_LIBRARY_DIRS})
    message(STATUS "Found openssl: ${OPENSSL_LIBRARY_DIRS}")
endif()

...
target_include_directories(${EXAMPLE_TARGET} PRIVATE ${EIXX_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS})
target_link_libraries(${EXAMPLE_TARGET} ${LINKLIBS} ${EIXX_LIBRARIES})
...

Shouldn't these lines include the basic_otp_node_local into the shared library? https://github.com/saleyn/eixx/blob/5c0baa3b820b07fca3a5880d972445aee38b46c1/src/CMakeLists.txt#L8-L16

saleyn commented 3 years ago

The lines 15,16 include that. Maybe you have EIXX_MARSHAL_ONLY=ON?

heri16 commented 3 years ago

Symbols in shared library:

symbols -arch x86_64 /usr/local/Cellar/eixx/1.4/lib/libeixx.dylib | grep basic_otp_node_local::basic_otp_node_local
                0x000000000000f900 (    0x80) eixx::connect::basic_otp_node_local::basic_otp_node_local(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts] 
                0x000000000000f980 (    0x75) eixx::connect::basic_otp_node_local::basic_otp_node_local(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts] 
                0x0000000000012062 (    0x52) eixx::connect::basic_otp_node_local::basic_otp_node_local(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (.cold) [FUNC, NameNList, MangledNameNList, Merged, NList, FunctionStarts] 
                0x00000000000120b4 (    0x51) eixx::connect::basic_otp_node_local::basic_otp_node_local(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (.cold) [FUNC, NameNList, MangledNameNList, Merged, NList, FunctionStarts] 

Linker error:

[100%] Built target
@(#)PROGRAM:ld  PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
        /usr/local/Cellar/eixx/1.4/lib
        /Users/heri/.asdf/installs/erlang/22.3.4.20/usr/lib
        /usr/local/Cellar/openssl@1.1/1.1.1k/lib
        /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/lib
Framework search paths:
        /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "eixx::connect::basic_otp_node_local::basic_otp_node_local(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      eixx::connect::basic_otp_node<std::__1::allocator<char>, std::__1::recursive_mutex>::basic_otp_node(boost::asio::io_context&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::allocator<char> const&, signed char) in matching_node.cpp.o
ld: symbol(s) not found for architecture x86_64

Looks like there is a symbol mismatch?

Seems to be the New ABI: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

saleyn commented 3 years ago

Strange. Maybe this is MacOS a specific bug? Not getting this error on Linux. Did you try defining _GLIBCXX_USE_CXX11_ABI in the project? Is this happening in both gcc and clang? I don't have a Mac, so never tried to build it on that OS.

heri16 commented 3 years ago

PR #50 now supports Clang which fixes this.

saleyn commented 3 years ago

When you address the comments in my review of #50, I'll merge.

heri16 commented 3 years ago

Fixed in PR #50 by supporting CLANG rather than defining _GLIBCXX_USE_CXX11_ABI.

Build on macOs:

brew install cmake boost openssl@1.1

git clone https://github.com/saleyn/eixx.git
cd eixx

rm -f .cmake-args.$(hostname)
echo "ENV:BOOST_ROOT=$(brew --prefix boost)" >> .cmake-args.$(hostname)
echo "ENV:OPENSSL_ROOT_DIR=$(brew --prefix openssl)" >> .cmake-args.$(hostname)
echo "DIR:INSTALL=/usr/local/Cellar/@PROJECT@/@VERSION@" >> .cmake-args.$(hostname)
echo "EIXX_MARSHAL_ONLY=OFF" >> .cmake-args.$(hostname)

make distclean
make bootstrap build=Release toolchain=clang
make