fmt icon indicating copy to clipboard operation
fmt copied to clipboard

Different visibility warning

Open xiaozhuai opened this issue 2 years ago • 10 comments

ld: warning: direct access in function 'fmt::v10::detail::format_error_code(fmt::v10::detail::buffer<char>&, int, fmt::v10::basic_string_view<char>)' from file '/usr/local/vcpkg/installed/x64-osx/lib/libfmt.a(format.cc.o)' to global weak symbol 'decltype(fp.begin()) fmt::v10::detail::parse_format_specs<int, fmt::v10::detail::compile_parse_context<char> >(fmt::v10::detail::compile_parse_context<char>&)' from file '/usr/local/vcpkg/installed/x64-osx/lib/libspdlog.a(spdlog.cpp.o)' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

When linking with spdlog on macOS, it shows this warning. And I've submit a pr in vcpkg to fix it. See https://github.com/microsoft/vcpkg/pull/35793

I just remove these lines and the warning disappeared https://github.com/fmtlib/fmt/blob/dbd9c89b3c1d4a92f15ab8296faec4507cf50ffb/CMakeLists.txt#L195-L205

But I'm not sure if it's the right fix.

xiaozhuai avatar Dec 21 '23 05:12 xiaozhuai

Could you provide a repro that doesn't involve vcpkg?

vitaut avatar Dec 21 '23 14:12 vitaut

Could you provide a repro that doesn't involve vcpkg?

@vitaut Sure, here is a minimal demo code which repro it. test_spdlog.zip

Just exec ./build.sh in test_spdlog directory under macOS and you will see this

image

Since we install fmt instead of addingfmt as a sub directory. FMT_MASTER_PROJECT will always be true.

xiaozhuai avatar Dec 21 '23 15:12 xiaozhuai

Hi @vitaut, any progress on this?

xiaozhuai avatar Dec 23 '23 16:12 xiaozhuai

I haven't looked into it. Also could you provide just the commands that use stock spdlog/fmt instead of a zip file?

vitaut avatar Dec 23 '23 17:12 vitaut

Also could you provide just the commands that use stock spdlog/fmt instead of a zip file?

Only 3 file in this zip.

xiaozhuai avatar Dec 24 '23 03:12 xiaozhuai

Unfortunately the repro doesn't work:

.../test_spdlog/vendor/spdlog/include/spdlog/fmt/fmt.h:32:14: fatal error: 'fmt/core.h' file not found
    #include <fmt/core.h>
             ^~~~~~~~~~~~

vitaut avatar Feb 04 '24 18:02 vitaut

One possible way to suppress the warning is annotating that function with FMT_VISIBILITY("default").

vitaut avatar Feb 04 '24 18:02 vitaut

@vitaut The master branch of spdlog and fmt is now incompatible. Please try this new repro which use fmt 10.0.0 test_spdlog_v2.zip

xiaozhuai avatar Feb 05 '24 05:02 xiaozhuai

Thanks for the updated repro. I don't see the visibility warning though, only:

ld: warning: ignoring duplicate libraries: '/Users/viz/Downloads/test_spdlog 2/install/lib/libfmt.a'

vitaut avatar Feb 17 '24 19:02 vitaut

@vitaut Please check this page https://github.com/xiaozhuai/test_spdlog/actions/runs/7947550191

macos-11 and macos-12 prints

ld: warning: direct access in function 'fmt::v10::detail::format_error_code(fmt::v10::detail::buffer<char>&, int, fmt::v10::basic_string_view<char>)' from file '/Users/runner/work/test_spdlog/test_spdlog/install/lib/libfmt.a(format.cc.o)' to global weak symbol 'decltype(fp.begin()) fmt::v10::detail::parse_format_specs<int, fmt::v10::detail::compile_parse_context<char> >(fmt::v10::detail::compile_parse_context<char>&)' from file '/Users/runner/work/test_spdlog/test_spdlog/install/lib/libspdlog.a(spdlog.cpp.o)' means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

macos-13 prints

ld: warning: ignoring duplicate libraries: '/Users/runner/work/test_spdlog/test_spdlog/install/lib/libfmt.a'

xiaozhuai avatar Feb 18 '24 08:02 xiaozhuai

Suppressed in https://github.com/fmtlib/fmt/commit/f68f452deaa15f222c7b2eee5f41c7a9bd249793. Thanks for reporting and putting together the repro.

vitaut avatar Feb 25 '24 19:02 vitaut