Problem
Building a C++23 project using std::print in CLion on Windows with the MinGW GCC toolchain fails with linker errors similar to the following:
undefined reference to `std::__open_terminal(_iobuf*)'
undefined reference to `std::__write_to_terminal(void*, std::span<char, 18446744073709551615ull>)'
collect2.exe: error: ld returned 1 exit statusCause
GCC 14 and later require linking against the stdc++exp experimental library when using C++23 features such as std::print or std::println on Windows. By default, this library is not linked, leading to undefined references during the build.
Resolution
Link the stdc++exp experimental library to your executable.
For example, in a CMake project:
- Add
target_link_libraries(<target name> stdc++exp)afteradd_executable(<target name> main.cpp)in theCMakeLists.txtfile. - In CLion, execute Tools | CMake | Reset Cache and Reload Project.
- Rebuild the project. The build should complete successfully.
Refer to the GCC documentation for more details: The GNU C++ Library Manual: Command Options.
Comments
0 comments
Please sign in to leave a comment.