# Linker error with import std example

**URL:** https://discourse.cmake.org/t/linker-error-with-import-std-example/14224
**Category:** Usage
**Tags:** os:macos, gen:ninja
**Created:** [June 11, 2025, 6:55pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224 "2025-06-11T18:55:28Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [June 11, 2025, 6:55pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/1 "2025-06-11T18:55:28Z")

</div>

I have this simple main.cxx:

```c++
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:

```cmake
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
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$ 

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [June 11, 2025, 6:58pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/2 "2025-06-11T18:58:17Z")

</div>

Also linker errors with clang-20:

```bash
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$ 

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 12, 2025, 5:02pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/3 "2025-06-12T17:02:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [June 12, 2025, 6:40pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/4 "2025-06-12T18:40:38Z")

</div>

No.

But at leased for clang, this helps:

**export LDFLAGS=“-L${LLVM\_ROOT}/lib/c++ -lc++abi -lc++”**

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [June 17, 2025, 3:46pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/5 "2025-06-17T15:46:12Z")

</div>

> [@ClausKlein](#):
>
> ```auto
> add_compile_options(-stdlib=libc++)
> add_link_options(-stdlib=libc++)
> 
> ```

I am guessing this is the cause of the trouble.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [June 17, 2025, 4:15pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/6 "2025-06-17T16:15:27Z")

</div>

Not on OSX

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 19, 2026, 9:33pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/7 "2026-02-19T21:33:57Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 20, 2026, 3:07pm UTC](https://discourse.cmake.org/t/linker-error-with-import-std-example/14224/8 "2026-02-20T15:07:16Z")

</div>

done, see [https://gitlab.kitware.com/cmake/cmake/-/issues/27626](https://gitlab.kitware.com/cmake/cmake/-/issues/27626)
