Open tdegeus opened 5 years ago
@jaredgrubb @Kerndog73 does any of you have time to help debug this?
I had some issues like this, IIRC it was a matter of using libstdc++11, i.e. add the define _GLIBCXX_USE_CXX11_ABI=1
when compiling your executable.
There are std::__cxx11
symbols in your shared lib, so I'd bet on this.
@theodelrieu Thanks for the suggestions. However, _GLIBCXX_USE_CXX11_ABI
is already set to 0
by stdexcept
. If I manually set it to 1
:
/home/travis/build/tdegeus/test_docopt.cpp/example/main.cpp:2: warning: "_GLIBCXX_USE_CXX11_ABI" redefined
1631 #define _GLIBCXX_USE_CXX11_ABI 1
1632
1633In file included from /usr/include/c++/8/exception:37,
1634 from /usr/include/c++/8/stdexcept:38,
1635 from /home/travis/miniconda/include/docopt/docopt_value.h:12,
1636 from /home/travis/miniconda/include/docopt/docopt.h:12,
1637 from /home/travis/build/tdegeus/test_docopt.cpp/example/main.cpp:1:
1638/usr/include/x86_64-linux-gnu/c++/8/bits/c++config.h:254: note: this is the location of the previous definition
1639 # define _GLIBCXX_USE_CXX11_ABI 0
Note that no matter if #define _GLIBCXX_USE_CXX11_ABI 0
or #define _GLIBCXX_USE_CXX11_ABI 1
the linker error keeps appearing (I also tried with supplying the define as compiler argument).
@tdegeus No I meant to pass -D_GLIBCXX_USE_CXX11_ABI=1
on the command line, instead of defining in the sources, it should work
@theodelrieu I tried also this by adding this to my CMakeLists.txt
target_compile_definitions(${PROJECT_NAME} PUBLIC "_GLIBCXX_USE_CXX11_ABI=1")
However...
[ 50%] Building CXX object CMakeFiles/Run.dir/main.cpp.o
1620/usr/bin/g++-7 -D_GLIBCXX_USE_CXX11_ABI=1 -isystem /home/travis/miniconda/include/docopt -O3 -DNDEBUG -std=gnu++14 -o CMakeFiles/Run.dir/main.cpp.o -c /home/travis/build/tdegeus/test_docopt.cpp/example/main.cpp
1640[100%] Linking CXX executable Run
1641/home/travis/miniconda/bin/cmake -E cmake_link_script CMakeFiles/Run.dir/link.txt --verbose=1
1642/usr/bin/g++-7 -O3 -DNDEBUG -rdynamic CMakeFiles/Run.dir/main.cpp.o -o Run -Wl,-rpath,/home/travis/miniconda/lib /home/travis/miniconda/lib/libdocopt.so
1643CMakeFiles/Run.dir/main.cpp.o: In function `main':
1644main.cpp:(.text.startup+0xe8): undefined reference to `docopt::docopt(std::string const&, std::vector<std::string, std::allocator<std::string> > const&, bool, std::string const&, bool)'
1645collect2: error: ld returned 1 exit status
Hmm, is it a visibility problem? What is the value of DOCOPT_API
here?
First of all, does it work with static linking? And header only?
This problem occurs with dynamic linking. More specifically I'm trying dynamic linking of the conda-forge package, build with this script:
https://github.com/conda-forge/docopt.cpp-feedstock/blob/master/recipe/build.sh
The failing example is here:
https://github.com/tdegeus/test_docopt.cpp/blob/master/example/main.cpp https://github.com/tdegeus/test_docopt.cpp/blob/master/example/CMakeLists.txt
Note that the example is failing on travis, but not on my own Linux machine.
Running c++filt
on your nm dump shows that the symbol is in the lib:
docopt::docopt(std::cxx11::basic_string<char, std::char_traits
, std::allocator cxx11::basic_string<char, std::char_traits> const&, std::vector<std:: , std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits , std::allocator cxx11::basic_string<char, std::char_traits> > > const&, bool, std:: , std::allocator > const&, bool)
Could you try to do the same with your local copy of libdocopt.so
?
Same
docopt::docopt(std::cxx11::basic_string<char, std::char_traits
, std::allocator cxx11::basic_string<char, std::char_traits> const&, std::vector<std:: , std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits , std::allocator cxx11::basic_string<char, std::char_traits> > > const&, bool, std:: , std::allocator > const&, bool)
Well, I have no idea :D
Do I need to enforce -D_GLIBCXX_USE_CXX11_ABI=1
also at the linking stage? And if so how do I do this in CMake?
No it's only at compile-time IIRC
@chrisdembia Do you have the same experience with the conda-forge package? I should state that it works fine on any of my macOS and Linux machine, just not in the CI. Could you comment?
I think I've seen this issue in the past, but I do not remember how I avoided it.
I do not see this linker issue with conda-forge: https://github.com/conda-forge/staged-recipes/pull/11894
...or with Travis CI: https://github.com/opensim-org/opensim-core/blob/master/.travis.yml
On the CI of my code I'm getting (on Linux only) the following linker error with the docopt.cpp feedstock:
To debug I created an isolated test repository with corresponding CI. As observed, the code compiles fine on macOS and Windows, but fails to compile on Linux. Interestingly, on my own Linux machine the code compiles without errors. Also, note that the file
/home/travis/miniconda/lib/libdocopt.so
is in fact linked.Output of
nm /home/travis/miniconda/lib/libdocopt.so
: