Vcpkg: Boost linker warnings on OSX

Created on 18 Oct 2018  路  2Comments  路  Source: microsoft/vcpkg

Hi vcpkg developers,

Now that I have my setup working reliably for OSX, Linux and Windows, I have a small nit to pick :-) I am seeing a lot of warnings on OSX like these [1]:

ld: warning: direct access in function 'void boost::throw_exception(boost::bad_weak_ptr const&)' from file '/tmp/vcpkg-export/installed/x64-osx/lib/libboost_log.a(text_file_backend.o)' to global weak symbol 'typeinfo for boost::exception_detail::clone_impl >' from file '/tmp/vcpkg-export/installed/x64-osx/lib/libboost_thread.a(thread.o)' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
...
ld: warning: direct access in function 'boost::exception_detail::clone_impl >::rethrow() const' from file '/tmp/vcpkg-export/installed/x64-osx/lib/libboost_log.a(text_file_backend.o)' to global weak symbol 'typeinfo for boost::exception_detail::clone_impl >' from file '/tmp/vcpkg-export/installed/x64-osx/lib/libboost_thread.a(thread.o)' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

Apparently these are caused by differing visibility settings [2] between my build and the build of Boost [3]. As per those comments, I have tried setting my build to fvisibility=hidden and fvisibility=default, with neither helping. This ticket [4] suggests recompiling Boost with:

cxxflags=-fvisibility=hidden
cxxflags=-fvisibility-inlines-hidden

I will try that next when I have some down time; meanwhile, has anyone experienced/solved this issue by any chance? To be honest, its nothing major but I thought I'd ask.

Many thanks for your time.

[1] https://my.cdash.org/viewBuildError.php?type=1&buildid=1545212
[2] https://gcc.gnu.org/wiki/Visibility
[3] https://stackoverflow.com/questions/36567072/why-do-i-get-ld-warning-direct-access-in-main-to-global-weak-symbol-in-this
[4] https://stackoverflow.com/questions/8685045/xcode-with-boost-linkerid-warning-about-visibility-settings/8685088#8685088

Most helpful comment

Actually, its probably worth mentioning that my project's CMakeLists.txt has the following:

    <snip>
    set(other_flags "${other_flags} -frtti -fvisibility-inlines-hidden")
    set(other_flags "${other_flags} -fvisibility=hidden")
    <snip>
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${other_flags}")

And that's why it worked - basically, all I did was to make vcpkg's Boost match my project's visibility settings. Your setup may differ.

All 2 comments

Quite remarkable, I did that change and I now have zero warnings on OSX! Can't quite believe it! :-) However, I'm not sure this is suitable for submission - not quite sure what the impact of this change is really. For what it's worth, here's the patch to my local tree:

diff --git a/ports/boost-modular-build-helper/CMakeLists.txt b/ports/boost-modular-build-helper/CMakeLists.txt
index dc4d13d..b0fe964 100644
--- a/ports/boost-modular-build-helper/CMakeLists.txt
+++ b/ports/boost-modular-build-helper/CMakeLists.txt
@@ -122,6 +122,9 @@ add_custom_target(boost ALL
         --hash
         -q

+        cxxstd=14
+        cxxflags=-fvisibility=hidden
+        cxxflags=-fvisibility-inlines-hidden
         architecture=x86
         threading=multi
         threadapi=pthread
diff --git a/toolsrc/CMakeLists.txt b/toolsrc/CMakeLists.txt
index a06cbae..834a459 100644
--- a/toolsrc/CMakeLists.txt
+++ b/toolsrc/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.3)
 project(vcpkg C CXX)

 OPTION(DEFINE_DISABLE_METRICS "Option for disabling metrics" OFF)
 if(CMAKE_COMPILER_IS_GNUXX OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
     set(GCC 1)
 elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")

I'm only doing this on OSX at present but I may look into doing it for Linux in the future when I fully understand the implications :-)

Actually, its probably worth mentioning that my project's CMakeLists.txt has the following:

    <snip>
    set(other_flags "${other_flags} -frtti -fvisibility-inlines-hidden")
    set(other_flags "${other_flags} -fvisibility=hidden")
    <snip>
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${other_flags}")

And that's why it worked - basically, all I did was to make vcpkg's Boost match my project's visibility settings. Your setup may differ.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhilLab picture PhilLab  路  3Comments

spindensity picture spindensity  路  3Comments

husseinalihazime picture husseinalihazime  路  3Comments

grandprixgp picture grandprixgp  路  3Comments

ThinkalVB picture ThinkalVB  路  3Comments