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

Fix "undefined reference to `fmt::v7::detail::basic_data<void>::digits'" #2333

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@
# endif
#else
# define FMT_CLASS_API
# if defined(__GNUC__) || defined(__clang__)
# define FMT_API __attribute__((visibility("default")))
# define FMT_EXTERN_TEMPLATE_API FMT_API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove FMT_EXTERN_TEMPLATE_API definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMT_EXTERN_TEMPLATE_API was added in the partial incorrect commit 13e6529 and is not used anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, "partial incorrect commit" 👎

FMT_EXTERN_TEMPLATE_API was used before. But you're correct to note that it is not necessary anymore.

# if defined(FMT_EXPORT) || defined(FMT_SHARED)
# if defined(__GNUC__) || defined(__clang__)
# define FMT_API __attribute__((visibility("default")))
# endif
# endif
#endif
#ifndef FMT_API
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ template <typename T = void> struct basic_data {
FMT_API static constexpr const char right_padding_shifts[] = {0, 31, 0, 1, 0};
};

#ifndef FMT_HEADER_ONLY
#ifdef FMT_SHARED
// Required for -flto, -fivisibility=hidden and -shared to work
extern template struct basic_data<void>;
#endif
Expand Down
15 changes: 15 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ if (FMT_PEDANTIC AND NOT WIN32)
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
endif ()

# This test are disabled on Windows because it is only *NIX issue.
if (FMT_PEDANTIC AND NOT WIN32)
add_test(static-export-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/static-export-test"
"${CMAKE_CURRENT_BINARY_DIR}/static-export-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
endif ()

# Activate optional CUDA tests if CUDA is found. For version selection see
# https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#cpp14-language-features
if (FMT_CUDA_TEST)
Expand Down
30 changes: 30 additions & 0 deletions test/static-export-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.1...3.18)

project(fmt-link CXX)

set(BUILD_SHARED_LIBS OFF)
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")

# Broken LTO on GCC 4
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
set(BROKEN_LTO ON)
endif ()

if (NOT BROKEN_LTO AND CMAKE_VERSION VERSION_GREATER "3.8")
# CMake 3.9+
include(CheckIPOSupported)
check_ipo_supported(RESULT HAVE_IPO)
if (HAVE_IPO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
endif ()

add_subdirectory(../.. fmt)
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)

add_library(library-test SHARED library.cc)
target_link_libraries(library-test PRIVATE fmt::fmt)

add_executable(exe-test main.cc)
target_link_libraries(exe-test PRIVATE library-test)
5 changes: 5 additions & 0 deletions test/static-export-test/library.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <fmt/compile.h>

__attribute__((visibility("default"))) std::string foo() {
return fmt::format(FMT_COMPILE("foo bar {}"), 4242);
}
6 changes: 6 additions & 0 deletions test/static-export-test/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include <string>

extern std::string foo();

int main() { std::cout << foo() << std::endl; }