Author Topic: Support for c++20 modules  (Read 46061 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Support for c++20 modules
« Reply #15 on: August 02, 2021, 03:52:44 pm »
Just expressing "support" is not enough, someone have to do the actual work :)
I don't have anything against adding support for the module system, I currently don't intend to do it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Waingrove

  • Single posting newcomer
  • *
  • Posts: 7
Re: Support for c++20 modules
« Reply #16 on: August 31, 2024, 06:42:07 pm »
I'm just starting out , again. And I'm learning on c++ 23. Using mingw64.14.1. It does support modules but I do not yet know how to precompile the module using codeblocks, yet. However using gcc is not difficult. Open a cmd in the folder of the project you are working on. Set the path for gcc , if you have not already done so. An example is  "set PATH=C:\Program Files\CodeBlocks\mingw64.14.1\bin;%PATH".  Run the following command: "g++ -std=c++2b -fmodules-ts -c -x c++ <filename.cppm>" .  g++ runs gcc, -std=c++2b : tells gcc to use c++23 , -fmodules-ts tells the compiler you are using modules, -c - Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file., -x forces gcc to use the language specified , c++ , then filename.cppm or however you label module file extension. If successfully built you should see a new folder gcm.cache. And a new object , filename.o in the root folder of your project.

If you figure out how to simply use codeblocks , respond.
« Last Edit: August 31, 2024, 06:46:15 pm by Waingrove »

Offline Krice

  • Almost regular
  • **
  • Posts: 174
Re: Support for c++20 modules
« Reply #17 on: October 31, 2024, 02:58:36 pm »
I think modules are trying to fix something in C++ that doesn't exist. No one wanted them and I'm quite sure many people wont use modules in C++ programming. This is just my opinion. It seems like current C++ developers are trying to "fix" the language, just like those who invented new "like C++ but better" languages: Java, D and C# just to name some of them. But they failed to understand that you can't fix something that works, you will be just changing to to another thing, possibly having new kind of problems which did happen with all those languages. They never fixed C++ or made a better version of it.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7791
    • My Best Post
Re: Support for c++20 modules
« Reply #18 on: October 31, 2024, 04:38:19 pm »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cacb

  • Lives here!
  • ****
  • Posts: 549
Re: Support for c++20 modules
« Reply #19 on: October 31, 2024, 09:31:46 pm »
I think modules are trying to fix something in C++ that doesn't exist.
I agree. I think codeblocks should support important new language features, but frankly I don't see the need for C++ modules. And someone would have to volunteer to do the job.

Offline JorgenBest

  • Single posting newcomer
  • *
  • Posts: 1
Re: Support for c++20 modules
« Reply #20 on: Yesterday at 06:51:01 pm »
I like to test the new module possibility and like it so far (just shortly started). I made a project template for using it with gcc or Clang (Arch Linux).

What I can do with modules:
1. use the std module with all library features for GCC  or CLang
2. create my own modules

Downside is:  when I add new modules I have to set the priority weight for compiling lower (e.g. to 10) for gcc. For Clang I need also to create a custom command to build and copy that in (copy the same code for every file).

See the attached main.cpp with a HelloWorld example. All other files can be constructed from this as well as the configuration in Codeblocks. I hope this helps, any one how likes to try modules.


I see two potential possibilities for what I provided: Others use these instructions to be able to work with modules from the Codeblocks IDE, even if it's not perfect.

Or secondly (what I would really like) an addition would be made to Codeblocks. Something (minimal?) like:
1. Add an build option: use C++modules (c++20 and higher should be selected) what adds the necessary compile options
2. Add an build option: use std module (this could add a std project file or create a compiled module in the project). Note the std module is not precompiled in gcc or clang, so the project has to do that, see my attachment.
3. Add the most used suffixes for modules and make those files compile in two steps: first create all the Compiled Module Interface (CMI) thus a gcm or pcm file. This has to be done before all other compilation and then create the object files.
4. Delete the CMI's when rebuilding / cleaning.

I think most of the needed functionality is already available in codeblocks for a solution to build modules. That's why I can make it work manually without too much trouble.

Note:
I doubt if giving 2 commands for clang in this custom build command is intended/allowed, but it works on my platform until now. The sequence of more than one commands seems to have different results than executing them from the command line (parallel execution?). For gcc I do both the CMI and object are made in one step (with standard compilation) and I only have to set the build priority so that's OK anyway.
If anything is not completely right I like to hear it, if it's not too much trouble. I didn't find complete documentation for custom build commands.

Note 2:
My solution builds the CMI's and object files of modules at the same time (but prior to other object files/main.o), so not according to point 3 of my proposal. This can lead to problems if modules have inter dependencies. Then the build weight should be used to build those modules in the right order.
Circular dependencies (that should be possible with modules as I understand) can't be build like that however. That's not really different from using headers I think. I don't know if I would use circular dependencies anyway. There's no easy way to couple 2 building commands to one C++ file in codeblocks and have them execute with different build weights. If I have to do that I need to trick codeblocks with empty files and custom build commands, what is not worth the trouble I think.
That's where an internal codeblock solution would be handy: if an extra building stage for CMI's was introduced prior to building object files the whole dependency handling would be very simple: just build the CMI's first.

I have no clue of the codeblocks source code, but I will be happy to help with what I can do regarding to modules.
« Last Edit: Yesterday at 09:25:37 pm by JorgenBest »