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

Necessary singletons are not exposed when compiling shared library with hidden visibility #463

Closed
ZijunH opened this issue Jun 3, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ZijunH
Copy link

ZijunH commented Jun 3, 2024

Consider the following toy example:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.21)

project(foo)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(CMAKE_BUILD_TYPE RelWithDebInfo)

add_subdirectory(quill)

add_library(logger_lib SHARED logger_lib.cpp)
target_link_libraries(logger_lib PUBLIC
  quill::quill
)

add_executable(logger logger.cpp)
target_link_libraries(logger PUBLIC
  logger_lib
)

logger_lib.cpp

#include "quill/Backend.h"
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/ConsoleSink.h"

[[gnu::visibility("default")]] quill::Logger* start_logger() {
    quill::Backend::start();

    auto console_sink = quill::Frontend::create_or_get_sink<quill::ConsoleSink>("sink_id_1");
    return quill::Frontend::create_or_get_logger("root", std::move(console_sink));
}

logger.cpp

#include "quill/Backend.h"
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/ConsoleSink.h"

quill::Logger* start_logger();

int main(){
  LOG_INFO(start_logger(), "This is a log info example {}", 123);
}

When compiled, the the logger does not print anything to the terminal. This is because the singletons (the static instance()) functions are not properly exposed in the shared library.

This is a similar issue to #222. Manually exporting the various static instance() functions by [[gnu::visibility("default")]] solves the issue on linux.

@odygrd
Copy link
Owner

odygrd commented Jun 3, 2024

Hey, thanks for reporting. I think I removed those since the library is header only i wasn't expecting it to build as shared library anymore. I will get it fixed over the next few days

@odygrd odygrd changed the title Necessary singletons are not exposed when compiling library with hidden visibility Necessary singletons are not exposed when compiling shared library with hidden visibility Jun 3, 2024
@odygrd odygrd added the enhancement New feature or request label Jun 3, 2024
@odygrd
Copy link
Owner

odygrd commented Jun 4, 2024

this is fixed with af9eb90

@odygrd odygrd closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants