Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Fix linker error: undefined reference to ...v2s_mt_posix.... on shared boost libs build #1484

Merged
merged 6 commits into from
Jul 9, 2018
Merged

Fix linker error: undefined reference to ...v2s_mt_posix.... on shared boost libs build #1484

merged 6 commits into from
Jul 9, 2018

Conversation

Bjoe
Copy link
Contributor

@Bjoe Bjoe commented Jul 2, 2018

Set in BoostConfig.cmake BOOST_LOG_DYN_LINK for Boost::log target to prevent linker error like:

undefined reference to ...v2s_mt_posix....

on shared lib build.

See also: https://www.boost.org/doc/libs/1_67_0/libs/log/doc/html/log/installation/config.html

Copy link
Owner

@ruslo ruslo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to prevent linker error like: undefined reference to ...v2s_mt_posix....

Can you please update Boost-log example to reproduce this error. Which toolchain/platform you have used?

@@ -150,3 +150,10 @@ endif()
if(TARGET Boost::chrono)
hunter_add_rt_library(Boost::chrono)
endif()

if(TARGET Boost::log AND NOT Boost_USE_STATIC_LIBS)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should analyze BUILD_SHARED_LIBS instead, it's used in Boost build scheme.

Like this:

if(TARGET Boost::log AND "@BUILD_SHARED_LIBS@")
   # ...
endif()

Copy link
Contributor Author

@Bjoe Bjoe Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is changed ... needs a test.

@Bjoe
Copy link
Contributor Author

Bjoe commented Jul 3, 2018

Can you please update Boost-log example to reproduce this error.

Well, how can I set the BUILD_SHARED_LIBS=ON on the example, like hunter_config(Boost VERSION 1.67.0-p1-secusmart CMAKE_ARGS BUILD_SHARED_LIBS=ON)

Which toolchain/platform you have used?

I doesn't matter. It's failing on all platforms/toolchain. Boost log use the C++ namespace as ABI :-) .... for example:
If you build boost log as shared on linux with posix thread support .... all namsapces are prefixd with:

.... v2_mt_posix .....

as static:

.... v2s_mt_posix.....

v2 = boost log version 2
s = static lib
mt = multi threaded
posix = posix thread

If you link against a boost log shared lib, you should add the BOOST_LOG_DYN_LINK to prevent the s prefix

Maybe I create in the future a pull request in the FindBoost from cmake .... should be fixed also there.

@ruslo
Copy link
Owner

ruslo commented Jul 3, 2018

Can you please update Boost-log example to reproduce this error

Well, how can I set the BUILD_SHARED_LIBS=ON on the example

Okay, not "update" but "create new", take a look at Boost-filesystem-shared:

I doesn't matter. It's failing on all platforms/toolchainti

Okay, just need one toolchain for CI testing.

@Bjoe
Copy link
Contributor Author

Bjoe commented Jul 6, 2018

I added a boost-log-shared example

I test the example with following command:

cmake -Hhunter/examples/Boost-log-shared -B~/Build/build-hunter-test -DCMAKE_TOOLCHAIN_FILE=~/Development/polly/clang-cxx14.cmake

It build on improve-boost-config and fails master branch with:

Development/hunter/examples/Boost-log-shared/foo.cpp:(.text+0x1a): undefined reference to »boost::log::v2s_mt_posix::trivial::logger::get()«

@@ -0,0 +1,375 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit by mistake ... it is removed.

find_package(Boost CONFIG REQUIRED log filesystem system chrono thread regex date_time atomic)

add_executable(foo foo.cpp)
target_link_libraries(foo
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean-up trailing whitespaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's clean-up

@@ -150,3 +150,10 @@ endif()
if(TARGET Boost::chrono)
hunter_add_rt_library(Boost::chrono)
endif()

if(TARGET Boost::log AND "@BUILD_SHARED_LIBS@")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are changing internal Boost files please update PACKAGE_INTERNAL_DEPS_ID of all files from cmake/projects/Boost directory. See:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated all PACKAGE_INTERNAL_DEPS_ID in cmake/projects/Boost

@@ -18,5 +18,5 @@ hunter_download(
Boost
PACKAGE_COMPONENT
atomic
PACKAGE_INTERNAL_DEPS_ID "31"
PACKAGE_INTERNAL_DEPS_ID "32"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update for PACKAGE_INTERNAL_DEPS_ID in hunter.cmake.in is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ups... sorry ... done.

@ruslo ruslo merged commit 5e32ac0 into ruslo:master Jul 9, 2018
@ruslo
Copy link
Owner

ruslo commented Jul 9, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants