Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot link shared library in C++14 or later #24

Closed
jbeich opened this issue Jul 10, 2018 · 2 comments
Closed

Cannot link shared library in C++14 or later #24

jbeich opened this issue Jul 10, 2018 · 2 comments

Comments

@jbeich
Copy link

jbeich commented Jul 10, 2018

After 7b6dcf6 the following doesn't work, breaking a number of consumers. Adding -DBOOST_NO_CXX14_CONSTEXPR appears to help. Is this intentional?

$ cat >a.cc
#include <boost/system/error_code.hpp>

int main()
{
  return 0;
}
$ pkg info -x boost
boost-libs-1.68.0.beta1.rc2

$ c++ -v
FreeBSD clang version 6.0.1 (tags/RELEASE_601/final 335540) (based on LLVM 6.0.1)
Target: x86_64-unknown-freebsd12.0
Thread model: posix
InstalledDir: /usr/bin

$ c++ a.cc -std=c++14 -I/usr/local/include -L/usr/local/lib -lboost_system
/usr/bin/ld: error: undefined symbol: boost::system::detail::generic_category_instance
>>> referenced by a.cc
>>>               /tmp/a-912c13.o:(boost::system::generic_category())
c++: error: linker command failed with exit code 1 (use -v to see invocation)
@jbeich
Copy link
Author

jbeich commented Jul 10, 2018

Ah, Boost.System itself has to be built with -std=c++14. I was building with -std=gnu++11, so Boost.Config auto-enabled cxx11_constexpr.

@jbeich jbeich closed this as completed Jul 10, 2018
@pdimov
Copy link
Member

pdimov commented Jul 10, 2018

Yes. I think I support the reverse case, linking from C++11 to a C++14-built System, but not this one. (And linking from 03 to 11 should work in both directions.) But in general this kind of thing (mixing C++ dialects) is unlikely to work.

woodsts pushed a commit to woodsts/buildroot that referenced this issue Oct 26, 2018
Commit f3a483a added -std=c++11 to
boost build if context is selected and gcc is at least 4.7 however it
has the side effect that cc-tool fails to find boost_system with the
following error if context and system is enabled with a gcc greater
than 6:

configure:16312: /home/dawncrow/buildroot-test/scripts/instance-0/output/host/bin/x86_64-linux-g++ -o conftest -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os   -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/home/dawncrow/buildroot-test/scripts/instance-0/output/host/x86_64-buildroot-linux-musl/sysroot/usr/include  -L/home/dawncrow/buildroot-test/scripts/instance-0/output/host/x86_64-buildroot-linux-musl/sysroot/usr/lib conftest.o -lboost_system -latomic >&5
conftest.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
conftest.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0x37): undefined reference to `boost::system::detail::generic_category_instance'

This error is related to the fact that since boost 1.68 and commit
boostorg/system@7b6dcf6,
boost system headers are now C++14 "by default" with gcc above 6:
- boostorg/system#24
- boostorg/system#26
- https://lists.boost.org/Archives/boost/2018/08/242770.php

So when building with gcc > 6, cc-tool thinks that boost has
generic_category_instance but because boost was compiled with
std=c++11, this function will not be in the library causing a link error

Instead of "hacking" even more boost, just remove -std=c++11 from
boost.mk and select BOOST_THREAD with gcc lower than 6

Fixes:
 - http://autobuild.buildroot.org/results/fc8f8a64751c751b2b66301967cc008509bbaa70

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Tested-by: Matt Weber <matthew.weber@rockwellcollins.com>
Reviewed-by: Ferdinand van Aartsen <ferdinand@ombud.nl>
Tested-by: Ferdinand van Aartsen <ferdinand@ombud.nl>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants