Undefined symbols for architecture x86_64: "initializer for module std" with g++-15

Open
#50 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
32/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cmake, cpp

Research direction

Reproduce the failure with the CMake and Ninja command shown in the issue, then inspect CMakeLists.txt and examples/scope-module.cpp, especially the scope-module target. Trace how the C++ standard module is configured and linked; done means the target links successfully on the reported macOS and GCC 15.2 setup.

Written by the indexing model from the issue text.

Description

see too https://discourse.cmake.org/t/cxx-modules-import-std-does-still-not-work-on-osx-with-g-15/15265
and https://discourse.cmake.org/t/header-only-libraries-and-c-20-modules/10680/13

bash-5.3$ make distclean
rm -rf build
bash-5.3$ make
cmake -S . -B build -G Ninja --log-level=DEBUG -D CMAKE_BUILD_TYPE=Release \
	 -D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD="d0edc3af-4c50-42ea-a356-e2862fe7a444" \
	 -D CMAKE_CXX_STDLIB_MODULES_JSON=/usr/local/Cellar/gcc/15.2.0/lib/gcc/current/libstdc++.modules.json \
	 -D CMAKE_CXX_STANDARD=23 -D CMAKE_CXX_EXTENSIONS=ON -D CMAKE_CXX_STANDARD_REQUIRED=ON \
	 -D CMAKE_CXX_MODULE_STD=ON \
	 -D CMAKE_INSTALL_MESSAGE=LAZY # XXX -D CMAKE_SKIP_INSTALL_RULES=ON # --fresh
-- The CXX compiler identification is GNU 15.2.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/g++-15 - skipped
-- Detecting CXX compile features
CMake Warning (dev) at /usr/local/share/cmake/Modules/Compiler/CMakeCommonCompilerMacros.cmake:248 (cmake_language):
  CMake's support for `import std;` in C++23 and newer is experimental.  It
  is meant only for experimentation and feedback to CMake developers.
Call Stack (most recent call first):
  /usr/local/share/cmake/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
  /usr/local/share/cmake/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
  CMakeLists.txt:5 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Detecting CXX compile features - done
Compiler is: GNU version:  15.2.0
cmake is: 4.2.0 modules scan :  1
-- Executing download step for catch2
'/usr/local/bin/cmake' '-E' 'rm' '-rf' '/Users/clausklein/Workspace/cpp/beman-project/scope/build/_deps/catch2-src'
'/usr/local/bin/git' 'clone' '--no-checkout' '--config' 'advice.detachedHead=false' 'https://github.com/catchorg/Catch2.git' 'catch2-src'
Cloning into 'catch2-src'...
'/usr/local/bin/git' 'checkout' 'v3.11.0' '--'
HEAD is now at b3fb4b9f v3.11.0
'/usr/local/bin/git' 'submodule' 'update' '--recursive' '--init'
'/usr/local/bin/cmake' '-E' 'copy' '/Users/clausklein/Workspace/cpp/beman-project/scope/build/CMakeFiles/fc-stamp/catch2/catch2-gitinfo.txt' '/Users/clausklein/Workspace/cpp/beman-project/scope/build/CMakeFiles/fc-stamp/catch2/catch2-gitclone-lastrun.txt'
-- Executing update step for catch2
-- Already at requested tag: v3.11.0
-- Executing patch step for catch2
-- Performing Test HAVE_FLAG__ffile_prefix_map__Users_clausklein_Workspace_cpp_beman_project_scope_build__deps_catch2_src__
-- Performing Test HAVE_FLAG__ffile_prefix_map__Users_clausklein_Workspace_cpp_beman_project_scope_build__deps_catch2_src__ - Success
Tests to be built: scope_success;scope_exit;scope_fail;unique_resource;module
Examples to be built: scope_example;unique_resource;unique_resource-file;scope-module
-- Configuring done (14.0s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/beman-project/scope/build
ln -sf build/compile_commands.json .
ninja -C build
ninja: Entering directory `build'
[251/260] Building CXX object examples/CMakeFiles/scope-module.dir/scope-module.cpp.o
/Users/clausklein/Workspace/cpp/beman-project/scope/examples/scope-module.cpp: In function 'int main()':
/Users/clausklein/Workspace/cpp/beman-project/scope/examples/scope-module.cpp:39:37: warning: name-independent declarations only available with '-std=c++2c' or '-std=gnu++2c' [-Wc++26-extensions]
   39 |         beman::scope::scope_success _([&success_ran] { success_ran = true; });
      |                                     ^
/Users/clausklein/Workspace/cpp/beman-project/scope/examples/scope-module.cpp:40:37: warning: name-independent declarations only available with '-std=c++2c' or '-std=gnu++2c' [-Wc++26-extensions]
   40 |         beman::scope::scope_fail    _([&fail_ran]    { fail_ran = true;    });
      |                                     ^
[252/260] Linking CXX executable examples/scope-module
FAILED: [code=1] examples/scope-module 
: && /usr/local/bin/g++-15 -stdlib=libstdc++ -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names examples/CMakeFiles/scope-module.dir/scope-module.cpp.o -o examples/scope-module  libbeman.scope.a && :
Undefined symbols for architecture x86_64:
  "initializer for module std", referenced from:
      __GLOBAL__sub_I_scope_module.cpp in scope-module.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
[253/260] Building CXX object _deps/catch2-build/src/CMakeFiles/Catch2.dir/catch2/matchers/catch_matchers_string.cpp.o
ninja: build stopped: subcommand failed.
make: *** [all] Error 1
bash-5.3$ 
Dominant language
C++
Stars
12
Forks
11
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bemanproject/scope

All issues in bemanproject/scope

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.