c++20 modules
amstradcpc

I can't get the c++20 modules to work, I get this message -> [Note] C++20 'import' only available with '-fmodules-ts', which is not yet enabled with '-std=c ++20'

I am using the devc++ ide of this page.
https://www.embarcadero.com/es/free-tools/dev-cpp

And the w64devkit compiler from this page.
https://github.com/skeeto/w64devkit/releases

Dizzy Egg

You probably will need to add -fmodules-ts to your compile options, but I do not know how to that with your IDE.

amstradcpc

.cpp

import persona;
#include <iostream>


int main(){
  Persona persona{ 21,80.20 };
  std::cout<<"edad: "<<persona.get_edad()<<"\n";
  std::cout<<"peso: "<<persona.get_peso()<<"\n";
  std::cout<<"modulos"<<"\n";
  return 0;
}

.cppm

#SelectExpand
1export module persona; 2 3export class Persona{ 4private: 5 int m_edad{}; 6 float m_peso{}; 7public: 8 Persona(int edad,float peso):m_edad{edad},m_peso{peso}{ 9 } 10 11 int get_edad(){ 12 return m_edad; 13 } 14 15 float get_peso(){ 16 return m_peso; 17 } 18};

This is the code that I am using for the test, I have used the -fmodules-ts command, in the tools options/compiler options but it still does not work

Dizzy Egg

For it to work in Visual Studio I had to add module; at the top of the module file, like this:

#SelectExpand
1module; //add this line 2export module persona; 3 4export class Persona{ 5private: 6 int m_edad{}; 7 float m_peso{}; 8public: 9 Persona(int edad,float peso):m_edad{edad},m_peso{peso}{ 10 } 11 12 int get_edad(){ 13 return m_edad; 14 } 15 16 float get_peso(){ 17 return m_peso; 18 } 19};

amstradcpc

It doesn't work either, I get these messages:

[Error] failed to read compiled module: No such file or directory
[Note] compiled module file is 'gcm.cache/persona.gcm'
[Note] imports must be built before being imported
[Error] returning to the gate for a mechanical issue

Dizzy Egg

Edited: it must be that your IDE needs additional parameters to build the module before using it in main…

amstradcpc

It may be but without knowing how it cannot be used.

Dizzy Egg

If you really want to use c++20 and modules, you may want to use a more complete IDE, like Visual Studio...

Thread #618780. Printed from Allegro.cc