12 ms·
C++20 Modules with GCC11
- glouwbug 5y agoI've been waiting half a decade for modules
- mhh__ 5y agoI'm pretty sure modules and concepts have basically taken my entire life to happen.
- bmurphy1976 5y agoHalf a decade? Man, I was hoping for something better than header files in the 90s!
- zigzag312 5y agoSo, for nearly one third of a century :P
- lelanthran 5y ago> Half a decade? Man, I was hoping for something better than header files in the 90s! It's hard to get something better than header files; modules don't provide the same functionality, as far as I can see. I think headers will remain purely for practical purposes.
- pjmlp 5y agoSince Mesa languages with modules also support conditional compilation and file inclusion. Check Modula-2 documentation, or Turbo Pascal for MS-DOS or Apple's Object Pascal.
- lelanthran 5y agoWell I did say "for practical purposes" :-) Header files serve as a library interface for almost all languages out there, and are so simple that for the most part they can automatically be used from other languages to access the library. C++ Modules, as far as I can tell anyway, are for C++ programs to use only, to access C++-only libraries.
- pjmlp 5y agoSince when do other languages compile C header files?
- lelanthran 5y ago> Since when do other languages compile C header files? I dunno, I never claimed that.
- pjmlp 5y ago> Header files serve as a library interface for almost all languages out there, and are so simple that for the most part they can automatically be used from other languages to access the library
- lelanthran 5y ago> Header files serve as a library interface for almost all languages out there, and are so simple that for the most part they can automatically be used from other languages to access the library What does that have to do with compilation? I use C headers all the time from Java projects and I've never had to compile them. Not manually anyway. Headers are usable from Python, Tcl, Lua, Java, C# and a whole lot of other languages that similarly don't require compilation and don't require much effort further than issuing a single command. The modules being proposed as a replacement for headers cannot, and will never, provide this functionality.
- pjmlp 5y ago
- dleslie 5y ago> Modules promise to significantly change the structure of C++ codebases and possibly signal headers’ ultimate demise (but probably not in my lifetime). It also opens the door to potentially have a unified build system and package manager, similar to Rust’s Cargo package manager; though I imaging standardising a unified build system would be one bloody battle. I wonder how many folks, like me, have stopped using C++ because it's too much effort to manage the build system and the overhead of headers adds too much to compile time? An enormous draw for alternatives, like Rust, Zig, Nim et al is that they simply don't have these problems.
- tempest_ 5y agoHonestly the modern build system is my favourite feature of rust. No messing with autoconfs, and make files that spit out some random gcc error I have to debug. To be fair however I am also not too interested in c++ and its 30 years of foot guns either so take it for what its worth.
- ridiculous_fish 5y agoHow does Rust handle problems like "call this function if it exists?" Is there support in build scripts?
- comex 5y agoIt doesn't. Indeed, when it comes to libc and other system libraries (or really most C libraries in general), the Rust ecosystem relies on hardcoding the ABI of every supported platform. It's theoretically possible to use bindgen (which parses C headers) as a build step, but this is rarely done.
- saagarjha 5y agoIn my experience Rust’s ability to rid itself from autoconf comes not because of any inherent benefits but because Rust code typically does not support systems where autoconf would really be required. For the mostly sane platform differences, the popular ones are probably hardcoded in some dependency crate with “-std” in its name so you don’t have to see it, unless of course it turns out to not support your less common platform or the check is broken, in which case you lob a GitHub issue at them and they deal with it.
- dathinab 5y agoI know this has to integrate with existing C++. But wow is that a multiple degrees more complex then in most other languages.
- asddubs 5y agoit's the C++ way
- otabdeveloper4 5y agoC++ supports platforms multiple degrees more complex than other languages. You're not gonna use Rust or Zig to write code for some obscure DSP CPU with a ridiculous architecture and no OS.
- tialaramex 5y agoActually, maybe you would choose Rust. The core consideration is going to be whether somebody is going to target LLVM on that CPU. If the CPU has a perfectly nice GCC backend then maybe Rust is a bad choice, but if it's LLVM anyway, or if "land an actual high level language on this hardware so that I don't need to write machine code by hand" is part of the goal of your work anyway, then Rust looks reasonable. Of course with no OS you can't run Rust's standard library as this expects OS services to underpin it. But you can have core features, and if you've got "no OS" you presumably were expecting to write anything you needed anyway. The reality for modern C++ is that you're on a Microsoft platform, or you're on GCC, or you're on Clang, there is no fourth vendor - you are screwed and nothing works. The era of $$$ proprietary compilers for weird targets on C++ ended and isn't coming back, C++ got too complicated for them and they gradually stopped implementing new features. But if you're on Clang you already have LLVM, which is a long way toward having Rust. If you're on a Microsoft platform that is the OS, I know, seems like they could do more but they didn't. When you say "ridiculous architecture" if you got too far off piste you can't have modern C++ either. Even as you stray into the black zone stuff gets very fragile and I wouldn't risk it. Your CPU integer arithmetic isn't technically required to be two's complement for example, but good luck fixing all the weird things that break if it isn't.
- dathinab 5y ago
- qweqwweqwe-90i 5y agoSo will clang, gcc, and msvc all have different implementations modules?
- steveklabnik 5y agoThey're different codebases, so as far as I know, they'll have different implementations, sure. But modules themselves are standardized, and so you should expect that after some time, you'll have stuff that works on all implementations. I don't believe that any of them are complete yet, which is why you see these differences currently. (Caveats: I have followed the development of modules semi closely but am by no means an expert.)
- not2b 5y agoThere's been a strong effort to have binary compatibility between compilers. The initial effort was funded by Intel when they launched Itanium and the resulting C++ ABI is used for other processor targets as well. So gcc, clang, and Intel's proprietary compiler are binary compatible modulo bugs. But modules are very new and I doubt if enough corner cases are nailed down yet.
- gumby 5y ago> So gcc, clang, and Intel's proprietary compiler are binary compatible modulo bugs. For generated code, definitely. But for example their standard libraries are different so you still can't, say, compile something in gcc that uses std::string and expect to be able to link it to something compiled with clang that uses std::string unless you are careful to use the headers (and .a files) of the same libc++ or libstdc++ I consider this a feature, not a bug -- diversity in implementation is a plus.
- summerlight 5y agoYeah, all the compilers will have different implementations and ABI and it'd be unrealistic expectation for them to be completely compatible. Instead, IIRC the current approach is to have a compatible format for specific common tasks. There has been some effort in SG15 to ensure consistency/interoperability across module implementations which led to https://wg21.link/P1688R0 https://wg21.link/P1688R0. This was mainly due to difficulty of scanning dependencies for build systems so there needs to be a standardized format to consume module information. One caveat: this group has been inactive for a while due to the pandemic, unfortunately.
- phibz 5y agoThis seems like it tries to be all things to all people. I wonder if it will succeed.
- copperx 5y agoI'm not sure if you're talking about modules or C++ itself.
- Shadonototro 5y agoIt's not, it still the same bullshit where you need to predeclare everything that is written bellow in your file or elsewhere C++20 modules from 60 years ago when people didn't know how to design modules They haven't looked at how languages such as D/Rust/Zig/Swift are doing, instead they went blind and they built a "new" thing with the limitations of their old design What a shame
- schaefer 5y agoso excited!
- baybal2 5y agoIn the C world, we have pkgconf. There is no real chance to see it becoming a part of the C standard, because C is just that compact, and simple. Yet, pkgconf will be a perfect base for pan-C package metadata standard outside of the standard.
- jcelerier 5y agopkgconf already sucks on Linux when your packages are configurable, and sucks even more on Windows
- lelanthran 5y ago> pkgconf already sucks on Linux when your packages are configurable, and sucks even more on Windows Yes, but to be fair most things suck on Windows because that userbase only recently decided that portability is a good thing. As we move forward and Microsoft products stop being the odd one out, the suckage will get lower.
- pjmlp 5y agoAh pkgconf now works on IBM, ARM, Sony, Nintendo, Unisys, Cisco, Green Hills, Apple, Google's platforms?
- lelanthran 5y agoNone of those systems you mention particularly care about portability, right? That means your pkgconf support on those platforms are going to be as broken as on Windows, if not more.
- pjmlp 5y agoWhat portability? Pkgconf is GNU/Linux only anyway.
- lelanthran 5y ago
- pkrumins 5y agoNow make a left-pad.cpp module and unpublish it.
- DerekL 5y agoThat joke doesn't even make sense. C++ modules aren't a package manager. They can't fetch code from a central repository.
- scrubs 5y agoAt the office c++ fans are using modules to fight back against the vast simplifications go, rust come with wrt to builds, dependency management. Alas modules are a step forward for c++ ... But ... * It'll be decades before our existing c++ code base is converted to modules meaning same cmake, dpkg, and all manner of nonsense ... * clibs used by c++ are not impacted * Modules are unlikely to help for os headers I'm trying to move to go when I can and pure rust otherwise. After many years of c++ build hell on top of legion internal c++ code .. building has become a cosmic pain in the butt.
- pjmlp 5y agoAnd 40 years of mature libraries.
- mtzet 5y agoIn my experience the important libraries I need to interact with are C libraries, not C++ libraries. Of course certain niches have very important C++ libraries, but I don't think the C++ library story in general is that great. Care to expand?
- fsloth 5y agoNot OP, but several domains have large non-trivial C++ codebases. For example, numerics, computational geometry and computer graphics have large mature libraries that would need to be rewritten by subject experts. The number of subject experts in these fields is not that large to start with, and the algorithms are complex and non-trivial, so "exothermic" explosion to new languages like Rust is unlikely to happen very fast.
- ziotom78 5y agoNot the OP, but the first libraries that come to my mind are Qt and wxWidgets (for GUI programming).
- pjmlp 5y agoCUDA, SYSCL, DP++, Qt, MFC and WinUI, Metal Shading Language, DirectX, most COM APIs in Windows, WinRT infrastructure, macOS IO/Driver Kit, ARM Mbed, Arduino, the native implementation of most well known ML libraries, all major game engines middleware, LLVM and GCC, just from the top of my head.
- gmueckl 5y agoNice post! When playing with modules, I noticed a major caveat that makes me dislike them very much: the standard says that modules must form acyclic graphs. This means you still cannot get rid of forward declarations and you must put interfaces and implementations into different files for any realistically sized code base. So, in terms of effort, you still have to maintain the equivalemt of headers, just with a different name and less preprocessor macro interference.
- hoseja 5y agoOh that's unfortunate.
- gmueckl 5y agoUnfortunate, yes. But it keeps with the spirit of a language that is designed for both single pass compilation and separate compilation. A module system that mimics other languages like D or Python (I don't know enough about rust) would require a major change to how C++ compilations works. The compilers are by now complex enough that I'm pretty sure that compiler developers aren't keen on rewriting their frontends for multi-pass compilation.
- creata 5y ago> I don't know enough about rust Rust allows cyclic dependencies between modules within a single crate, but not between crates.
- pjmlp 5y agoThat is true of most module systems anyway, and it was already an huge battle to get them adopted at all.
- gmueckl 5y agoWhich module systems are you thinking of? The only ones that I think come close are the ones in Pascal and its successors.
- tdiff 5y agoUnfortunately modules support in major build systems (e.g. cmake) is falling behind, and without it modules are somewhat useless for general c++ projects. I've only heard of build2 having some support for modules.
- pjmlp 5y agoVisual Studio's MSBuild is doing quite alright, https://devblogs.microsoft.com/cppblog/moving-a-project-to-cpp-named-modules/ https://devblogs.microsoft.com/cppblog/moving-a-project-to-c...
- Shadonototro 5y agoI was waiting for C++20 modules to finally come back to using C++ again.. and what a disapointment You still have to predeclare everything......... and you can't have circular dependency.... They learnt nothing, and they missed an opportunity to be relevant again C++ is definitely dead, at least to me This is so sad..
- deleted 5y ago[deleted]