CESNET / libyang-cpp

C++ bindings for the libyang library
https://gerrit.cesnet.cz/q/project:CzechLight/libyang-cpp
BSD 3-Clause "New" or "Revised" License
10 stars 7 forks source link

make fails on osx arm64 #7

Closed sevenb23 closed 1 year ago

sevenb23 commented 1 year ago

I'm trying to install on the below arm64-apple-darwin22.1.0. make stage breaks with the following error

Undefined symbols for architecture arm64:
  "libyang::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, libyang::NodeType const&)", referenced from:
      doctest::detail::filldata<libyang::NodeType>::fill(std::__1::basic_ostream<char, std::__1::char_traits<char> >*, libyang::NodeType const&) in schema_node.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [test_schema_node] Error 1
make[1]: *** [CMakeFiles/test_schema_node.dir/all] Error 2
make: *** [all] Error 2

Is the platform not supported ? compiler : Apple clang version 14.0.0 (clang-1400.0.29.202)

syyyr commented 1 year ago

It could have something to do with these lines: https://github.com/CESNET/libyang-cpp/blob/master/include/libyang-cpp/Enum.hpp#L295-L302

std::ostream& operator<<(std::ostream& os, const NodeType& type)
#if defined(__GNUC__) && !defined(__llvm__) && __GNUC__ <= 10
    LIBYANG_CPP_EXPORT
#endif
    ;
std::ostream& operator<<(std::ostream& os, const ErrorCode& err)
#if defined(__GNUC__) && !defined(__llvm__) && __GNUC__ <= 10
    LIBYANG_CPP_EXPORT
#endif
    ;

I'm not sure if apple arm needs the LIBYANG_CPP_EXPORT macro or not. Although if you're using clang, then __llvm__ is surely defined? So maybe LIBYANG_CPP_EXPORT is needed after all? Unfortunately, I don't have an Apple arm device to test this.

jktjkt commented 1 year ago

I got a similar error when building via GitHub CI with GCC 11.3 on OS X 13 (targetting 12.4), but this time for x86_64. I.e., a different compiler, and a different architecture:

FAILED: test_schema_node 
: && /usr/local/bin/g++-11 -Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough -Wsuggest-override  -O3 -DNDEBUG -arch x86_64 -isysroot /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.4 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o -o test_schema_node  -Wl,-rpath,/Users/runner/work/oopt-gnpy-libyang/build-libyang-cpp  libDoctestIntegration.a  libyang-cpp.dylib && :
Undefined symbols for architecture x86_64:
  "__ZN7libyanglsERSoRKNS_8NodeTypeE", referenced from:
      __ZN7doctest6detail19stringifyBinaryExprIN7libyang8NodeTypeES3_EENS_6StringERKT_PKcRKT0_ in schema_node.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

I'll take a look into this.

jktjkt commented 1 year ago

@sevenb23 , does this patch work for you?

jktjkt commented 1 year ago

Fixed via https://github.com/CESNET/libyang-cpp/commit/510d5ac5fe5f4da4acd191b83c4ba7e17aea344d