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

Different visibility warning #3769

Closed
xiaozhuai opened this issue Dec 21, 2023 · 11 comments
Closed

Different visibility warning #3769

xiaozhuai opened this issue Dec 21, 2023 · 11 comments

Comments

@xiaozhuai
Copy link

xiaozhuai commented Dec 21, 2023

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 microsoft/vcpkg#35793

I just remove these lines and the warning disappeared

fmt/CMakeLists.txt

Lines 195 to 205 in dbd9c89

if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
set_verbose(CMAKE_CXX_VISIBILITY_PRESET hidden CACHE STRING
"Preset for the export of private symbols")
set_property(CACHE CMAKE_CXX_VISIBILITY_PRESET PROPERTY STRINGS
hidden default)
endif ()
if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
set_verbose(CMAKE_VISIBILITY_INLINES_HIDDEN ON CACHE BOOL
"Whether to add a compile flag to hide symbols of inline functions")
endif ()

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

@vitaut
Copy link
Contributor

vitaut commented Dec 21, 2023

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

@xiaozhuai
Copy link
Author

xiaozhuai commented Dec 21, 2023

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
Copy link
Author

Hi @vitaut, any progress on this?

@vitaut
Copy link
Contributor

vitaut commented Dec 23, 2023

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

@xiaozhuai
Copy link
Author

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

Only 3 file in this zip.

@vitaut
Copy link
Contributor

vitaut commented Feb 4, 2024

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
Copy link
Contributor

vitaut commented Feb 4, 2024

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

@xiaozhuai
Copy link
Author

@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

@vitaut
Copy link
Contributor

vitaut commented Feb 17, 2024

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'

@xiaozhuai
Copy link
Author

xiaozhuai commented Feb 18, 2024

@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'

@vitaut
Copy link
Contributor

vitaut commented Feb 25, 2024

Suppressed in f68f452. Thanks for reporting and putting together the repro.

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