Linker error with import std example

I have this simple main.cxx:

import std;

int main(int argc, char* argv[])
{
  if (argc > 0 && argv[0]) {
    std::string argv0 = argv[0];
    std::print("program: {}/n", argv0);
  }
  return 0;
}

and this CMakeLists.txt:

set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")

cmake_minimum_required(VERSION 3.29...4.0)
project(cxx_modules_import_std CXX)

set(CMAKE_CXX_MODULE_STD 1)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    add_compile_options(-stdlib=libc++)
    add_link_options(-stdlib=libc++)
endif()

add_executable(main main.cxx)
target_compile_features(main PRIVATE cxx_std_26)
# TBD: target_link_libraries(main PRIVATE c++)

enable_testing()
add_test(NAME main COMMAND main)

and get this linker error:

bash-5.2$ CXX=g++-15 CC=gcc-15 ~/.local/bin/cmake -S . -B build --fresh -D CMAKE_CXX_STANDARD=26
-- The CXX compiler identification is GNU 15.1.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 /Users/clausklein/.local/share/cmake-4.0/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):
  /Users/clausklein/.local/share/cmake-4.0/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
  /Users/clausklein/.local/share/cmake-4.0/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
  CMakeLists.txt:4 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Detecting CXX compile features - done
-- Configuring done (5.4s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Downloads/cmake/Tests/RunCMake/CXXModules/examples/import-std/build
bash-5.2$ ninja -C build
ninja: Entering directory `build'
[8/8] Linking CXX executable main
FAILED: main 
: && /usr/local/bin/g++-15  -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/main.dir/main.cxx.o -o main   && :
Undefined symbols for architecture x86_64:
  "initializer for module std", referenced from:
      __static_initialization_and_destruction_0() in main.cxx.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
bash-5.2$ 

Also linker errors with clang-20:

bash-5.2$ CXX=clang++ CC=clang ~/.local/bin/cmake -S . -B build --fresh -D CMAKE_CXX_STANDARD=26
-- The CXX compiler identification is Clang 20.1.6
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/Cellar/llvm/20.1.6/bin/clang++ - skipped
-- Detecting CXX compile features
CMake Warning (dev) at /Users/clausklein/.local/share/cmake-4.0/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):
  /Users/clausklein/.local/share/cmake-4.0/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
  /Users/clausklein/.local/share/cmake-4.0/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
  CMakeLists.txt:4 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Detecting CXX compile features - done
-- Configuring done (9.6s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Downloads/cmake/Tests/RunCMake/CXXModules/examples/import-std/build
bash-5.2$ ninja -C build
ninja: Entering directory `build'
[10/10] Linking CXX executable main
FAILED: main 
: && /usr/local/Cellar/llvm/20.1.6/bin/clang++  -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libc++ CMakeFiles/main.dir/main.cxx.o -o main  lib__cmake_cxx26.a && :
Undefined symbols for architecture x86_64:
  "std::__1::__is_posix_terminal(__sFILE*)", referenced from:
      std::__1::__print::__is_terminal[abi:ne200100](__sFILE*) in main.cxx.o
ld: symbol(s) not found for architecture x86_64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
bash-5.2$ 

Are you trying to do multiarch? AFAIK, BMI files are a single architecture at the moment.

No.

But at leased for clang, this helps:

export LDFLAGS=“-L${LLVM_ROOT}/lib/c++ -lc++abi -lc++”

I am guessing this is the cause of the trouble.

Not on OSX

Could you please file an issue to track this? It looks like the initializer symbol may need an extra link on macOS for clang-20?