[Bug c++/107084] New: Program does not link with Standard Library Header Unit but with correspoding #include
karl.weber99 at gmx dot net
gcc-bugzilla@gcc.gnu.org
Thu Sep 29 09:59:27 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107084
Bug ID: 107084
Summary: Program does not link with Standard Library Header
Unit but with correspoding #include
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: karl.weber99 at gmx dot net
Target Milestone: ---
When I compile iostream with
g++ -fmodules-ts -std=c++20 -c -x c++-system-header iostream
and use "import <iostream>;" the program does not link. When I use "#include
<iostream>" instead, it does link and run.
Commands:
=============================================
g++ -fmodules-ts -std=c++20 -c -x c++ employee.cppm
g++ -fmodules-ts -std=c++20 -c structtest_fmt.cpp
g++ -o structtest structtest_fmt.o employee.o -lfmt
/usr/bin/ld: structtest_fmt.o: in function `main':
structtest_fmt.cpp:(.text+0xfb): undefined reference to
`fmt::v9::vformat(fmt::v9::basic_string_view<char>,
fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender,
char> >)'
/usr/bin/ld: structtest_fmt.cpp:(.text+0x1ae): undefined reference to
`fmt::v9::vformat(fmt::v9::basic_string_view<char>,
fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender,
char> >)'
/usr/bin/ld: structtest_fmt.cpp:(.text+0x261): undefined reference to
`fmt::v9::vformat(fmt::v9::basic_string_view<char>,
fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender,
char> >)'
/usr/bin/ld: structtest_fmt.o: in function
`std::allocator_traits<std::allocator<char>
>::deallocate(std::allocator<char>&, char*, unsigned long)':
structtest_fmt.cpp:(.text._ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm[_ZNSt16allocator_traitsISaIcEE10deallocateERS0_Pcm]+0x2d):
undefined reference to `std::__is_constant_evaluated()'
collect2: error: ld returned 1 exit status
=============================================
employee.cppm
=============================================
export module employee;
export struct Employee {
char firstInitial;
char lastInitial;
int employeeNumber;
int salary;
};
=============================================
structtest_fmt.cpp
=============================================
#include <fmt/format.h>
import <iostream>;
import employee;
using namespace std;
int main()
{
// create and populate an employee
Employee anEmployee;
anEmployee.firstInitial = 'J';
anEmployee.lastInitial = 'D';
anEmployee.employeeNumber = 42;
anEmployee.salary = 80000;
// output the values of an employee
cout << fmt::format("Employee: {}{}", anEmployee.firstInitial,
anEmployee.lastInitial) << endl;
cout << fmt::format("Number: {}", anEmployee.employeeNumber) << endl;
cout << fmt::format("Salary: ${}", anEmployee.salary) << endl;
}
=============================================
When I replace the import iostream by the corresponding include statement (and
delete iostream.gcm, then is compiles, links and runs successfully.
More information about the Gcc-bugs
mailing list