Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » c++20 modules

This thread is locked; no one can reply to it. rss feed Print
c++20 modules
amstradcpc
Member #23,651
January 2023

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
Member #10,824
March 2009
avatar

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

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

amstradcpc
Member #23,651
January 2023

.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
Member #10,824
March 2009
avatar

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};

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

amstradcpc
Member #23,651
January 2023

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
Member #10,824
March 2009
avatar

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

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

amstradcpc
Member #23,651
January 2023

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

Dizzy Egg
Member #10,824
March 2009
avatar

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

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Go to: