https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103629
--- Comment #8 from Mathieu Malaterre <mathieu.malaterre at gmail dot com> ---
% more CMakeLists.txt main.cc Module.cc openvdb.cc Tree.h
::::::::::::::
CMakeLists.txt
::::::::::::::
cmake_minimum_required(VERSION 3.13)
project(p)
# only export limited set of symbols
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# important to have pthread at runtime:
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
# important to use SHARED:
add_library(openvdb SHARED openvdb.cc)
target_include_directories(openvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(vdb_view main.cc Module.cc)
target_link_libraries(vdb_view openvdb Threads::Threads)
target_include_directories(vdb_view PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
::::::::::::::
main.cc
::::::::::::::
void initialize();
int main(int , char *[])
{
initialize();
return 0;
}
::::::::::::::
Module.cc
::::::::::::::
#include "Tree.h"
class Module
{
void init();
};
void Module::init() // no-inline
{
Tree::treeType();
}
::::::::::::::
openvdb.cc
::::::::::::::
#include "Tree.h"
static std::string do_segfault() { return Tree::treeType(); }
__attribute__((visibility("default")))
void initialize()
{
do_segfault();
}
::::::::::::::
Tree.h
::::::::::::::
#pragma once
#include <mutex>
#include <memory>
class Tree
{
public:
static const std::string treeType() {
static std::once_flag once;
std::call_once(once, []() {
sTreeTypeName.reset(new std::string());
});
return *sTreeTypeName;
}
private:
static std::unique_ptr<const std::string> sTreeTypeName;
};
std::unique_ptr<const std::string> Tree::sTreeTypeName;