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

Header-only mode not linking with fmt::ostream #3952

Closed
breyerml opened this issue May 7, 2024 · 1 comment
Closed

Header-only mode not linking with fmt::ostream #3952

breyerml opened this issue May 7, 2024 · 1 comment

Comments

@breyerml
Copy link

breyerml commented May 7, 2024

Fmt fails to link in header-only mode if fmt::ostream is used on the last release and the current master.

Minimal example to reproduce:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.1...3.29)

project(
  test
  VERSION 1.0
  LANGUAGES CXX)

add_executable(prog main.cpp)

include(FetchContent)
FetchContent_Declare(fmt
                     GIT_REPOSITORY https://github.com/fmtlib/fmt.git
                     GIT_TAG 57593a1
                     QUIET
                     EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(fmt)
target_link_libraries(prog PUBLIC fmt::fmt-header-only)

main.cpp:

#include "fmt/os.h"

int main() {
  fmt::ostream out = fmt::output_file("test.txt");
  out.print("foo");
  return 0;
}

Compiled via:

cmake -B build .
cmake --build build

results in the linker error:

[ 20%] Building CXX object CMakeFiles/prog.dir/main.cpp.o
[ 40%] Linking CXX executable prog
/usr/bin/ld: CMakeFiles/prog.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x80): undefined reference to `fmt::v10::ostream::~ostream()'
/usr/bin/ld: main.cpp:(.text+0xa6): undefined reference to `fmt::v10::ostream::~ostream()'
/usr/bin/ld: CMakeFiles/prog.dir/main.cpp.o: in function `fmt::v10::ostream::ostream(fmt::v10::basic_cstring_view<char>, fmt::v10::detail::ostream_params const&)':
main.cpp:(.text._ZN3fmt3v107ostreamC2ENS0_18basic_cstring_viewIcEERKNS0_6detail14ostream_paramsE[_ZN3fmt3v107ostreamC5ENS0_18basic_cstring_viewIcEERKNS0_6detail14ostream_paramsE]+0x2b): undefined reference to `fmt::v10::detail::file_buffer::file_buffer(fmt::v10::basic_cstring_view<char>, fmt::v10::detail::ostream_params const&)'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/prog.dir/build.make:97: prog] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/prog.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

Tested with GCC 11.4.0, icpx 2024.0.2, and nvc++ 24.3-0.

@vitaut
Copy link
Contributor

vitaut commented May 9, 2024

Same as #3708.

@vitaut vitaut closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants