#Getting `import std` to work

1 messages · Page 1 of 1 (latest)

glacial current
#

I'm currently messing around with llvm 17 on windows and since this is the bleeding edge, there aren't any resources online for this.

Has anyone already done this?

main.cpp

import std;

int main()
{
  std::cout << "Hello, World!"
}
PS C:\Users\samsk\mtest> clang++ -std=c++23 -fmodules main.cpp         
main.cpp:1:8: fatal error: module 'std' not found
    1 | import std;
      | ~~~~~~~^~~
1 error generated.
PS C:\Users\samsk\mtest> 

just as a note, creating my own custom modules with cmake works just fine (3.28-rc1 is available now!) it's just that import std doesn't work.

hybrid tideBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

raw lance
#

afaik you have to build the std module yourself and supply it like any other module

#

and I'd guess that's probably just how it's gonna be. anything else comes with a whole host of issues that don't really have good solutions. this is really smth that just needs to be considered in the build system.

#

I think best we can hope for is that compilers will just have some way to find the source for the std module so that it can be built like any other module dependency

glacial current
raw lance
#

I believe msvc should ship such a file. but I have no idea whether clang supports that atm.

glacial current
#

well there's some level of integration so far.

export import <iostream>;

yields

Error while scanning dependencies for C:/Users/samsk/mtest/foo.cxx:
C:/Users/samsk/mtest/foo.cxx:7:15: error: header file <iostream> (aka 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\iostream') cannot be imported because it is not known to be a header unit

where would that file be because if I can just point the compiler there that would work.

raw lance
#

you need to tell the compiler what modules exits and where to find them

#

I'm not exactly sure what interface clang has for this

#

iirc they used to have these module map files

#

but no idea what the current standard modules implementation uses

glacial current
#

ive got absolutely no idea

#

I did some looking through the clang documentation and couldnt find how to give it a custom module pat

#

ill just wait for someone to make an article or something on it

raw lance
#

I think @tardy halo might know smth

glacial current
#

that'd be helpful

#

since its just import std that I cant figure out

#

normal modules work just fine

#

i've been wanting to ditch headers for basically asl ong as ive known about them

raw lance
#

how do normal modules work?

glacial current
#

as in like custom modules

#

like

raw lance
#

like, you need to build and consume those too?

glacial current
#
module;

#include <iostream>

export module foo;

export class foo {
public:
  foo();
  ~foo();
  void helloworld();
};

foo::foo() = default;
foo::~foo() = default;
void foo::helloworld() {
  std::cout << "hello world\n";
  ;
}
#

like this

#

this works fine

raw lance
#

yeah but you need to compile this module and then tell clang where to find it when compiling the file that consumes the module?

glacial current
#
import foo;

int main() {
  foo f;
  f.helloworld();
}
module;

#include <iostream>

export module foo;

export class foo {
public:
  foo();
  ~foo();
  void helloworld();
};

foo::foo() = default;
foo::~foo() = default;
void foo::helloworld() {
  std::cout << "hello world\n";
  ;
}
glacial current
#

3.28 has module integration

#

i'm using 3.28-rc1

raw lance
#

oh

glacial current
#
cmake_minimum_required(VERSION 3.28)
project(std_module_example CXX)

set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 23)
add_library(foo)
target_sources(foo
  PUBLIC
    FILE_SET cxx_modules TYPE CXX_MODULES FILES
    foo.cxx
)
add_executable(hello main.cxx)
target_link_libraries(hello PRIVATE foo)
#

thats why im screwing around with it right now

raw lance
#

yeah ok, I though you're building manually via command line

glacial current
#

nope

#

that doesnt scale

raw lance
#

ofc not

#

but then this is just an issue of cmake not supporting this yet

glacial current
#

almost certnally

raw lance
#

I guess?

glacial current
#

however

raw lance
#

unless they have smth

glacial current
#

I did try this on my mac yesterday and import std worked just fine

#

with the commeand

raw lance
#

no idea, I try to avoid cmake as much as possible

glacial current
#

clang++ -std=c++23 -fmodules main.cpp

#

and import std just worked

#

¯_(ツ)_/¯

raw lance
#

well 🤷‍♂️

#

I guess clang + libc++ has support for that or smth

glacial current
#

Id guess so

#

I was using clang17 installed via homebrew

raw lance
#

msvc requires you to build it afaik

glacial current
#

which uses its own bundled libstdc++

glacial current
#

I just dont want to wait 😄

raw lance
#

^^

glacial current
#

ive been waiting for modules for like 2 years, basically when I started using C++

hybrid tideBOT
#

@glacial current Has your question been resolved? If so, run !solved :)

glacial current
#

``16u ;