I've been trolling through the messages and haven't found an updated answer to Xcode support for C++20 modules. Apologies if I missed it.
Right now, all I'm trying to do is use the import directive to import a C++ Standard Library file.
import <iostream>;
import <string>;
import <memory>;
This produces an error of "Use of undeclared identifier 'iostream'" as well as "Use of undeclared identifier 'string'" (same for memory).
For my Project Build Settings I have:
My C++ Language Dialect: GNU++20 [-std=gnu++20]
Compile for C/C++/Objective-C: Default compiler (Apple Clang)
Would appreciate help with this. Thank you.
Related
Sorry if i ask again about "moudules" in C++.
Im using g++ gcc-c++-12.2.1-4.fc37.x86_64 in fedora 37 linux and vscode.
So i said: i will upgrade my knowladge with the book "A tour of C++ third edition" which its updated to c++20 standard.
The thing that the first program:
import std;
int main()
{
std::cout << "Hello, World!\n";
}
Doesn't compile.
I have enabled "std=c++20" and "-fmodules-ts" and also tried "-std=gnu++20".
The output is this, its like the compiled modules are missing:
std: error: failed to read compiled module: No existe el fichero o el directorio
std: nota: compiled module file is ‘gcm.cache/std.gcm’
std: nota: imports must be built before being imported
std: error fatal: returning to the gate for a mechanical issue
Ok it's in spanish becouse is my native tongue.
Any help?
import std;
This line of code requires not only module support, but also Standard Library Modules (P2465R3 Standard Library Modules std and std.compat) that's part of C++23.
From the Compiler support for C++23 page on cppreference, we can see that it's still not supported by GCC libstdc++.
As OP mentioned that the code snippet is taken from Bjarne's book, I double-checked section 1.2 of it. In the paragraph after the next from the code snippet containing import std;, it's stated that this is not yet standard:
The import directive is new in C++20 and presenting all of the standard library as a module std is not yet standard. [...]
When I try to use import statements within C++20 with the modules feature under a Windows environment, I am not able to make it work because I must doing something wrong.
The key thing is that I tried different options on the cmd args without success (take any possible variation), like:
-fimplicit-modules -fbuiltin-module-map -fimplicit-module-maps
what relegates me to the use of the #include directives in the module purview, and it's provoking this kind of bug (related question Clang error including headers in C++ projects)
How does Clang should be instructed in order to find the modulemap that enables the usage of import statements for system headers under Windows (MSVC toolchain assumed).
Thanks.
I don't understand why
I saw import std.core; here
I can't import std;
I can't import std.iostream;
I can #include <iostream>
Can you explain why above is happening? Maybe i guess std.iostream is not a module. Then why 1. works?
#Someprogrammerdue provided this reference, and its says
import <iostream>; // import declaration
When I run following in my compiler
import <iostream>;
int main()
{
return 0;
}
I get
main.cpp:1:8: error: 'iostream' was not declared in this scope
1 | import<iostream>;
Why is this happening?
I don't understand why
I saw import std.core; here
You saw what you did because you read the page and that's what was written there.
I can't import std;
This is because the C++20 standard library doesn't define modules. And because no other library can (or shouldn't) define module std because that module name is reserved for language implementation / future standardisation.
I can't import std.iostream;
See 2.
I can #include <iostream>
That header is part of the C++20 standard library.
Then why 1. works?
The MSVC documentation explains:
Although not specified by the C++20 standard, Microsoft enables its implementation of the C++ Standard Library to be imported as modules.
P.S. Support for modules is at the moment of writing only partially implemented by all major compilers with the exception of MSVC which appears to have full implementation since 19.28 (the modular standard libary is not a requirement for this).
P.P.S. Modular standard library is planned for C++23.
import std;
Improvement in compilation time.
According to ISO C++23, there is also import std.compat;.
Differences between the two are as follows (extracted from P2465R3):
import std; imports everything in namespace std from C++ headers (e.g. std::sort from <algorithm>) and C wrapper headers (e.g. std::fopen from <cstdio>). It also imports ::operator new etc. from <new>.
import std.compat; imports all of the above, plus the global namespace counterparts for the C wrapper headers (e.g. ::fopen).
import ... is said to be much faster to compile than #include ....
Interview with Bjarne Stroustrup (InfoWorld): C++ 23 to introduce module support.
P.S. Modules are not supported fully by most compilers yet. For MSVC users, please, refer to this link.
(https://learn.microsoft.com/en-us/cpp/cpp/tutorial-import-stl-named-module?view=msvc-170).
Environment:
Framework: Qt 5.12.9
Compiler: MSVC 15.9.28307.1234 (x64)
Debugger: CDB 10.017763.132 (x64)
Standard: C++11
Editor: Qt Creator 4.12.2
OS: Win10 Enterprise 1809
I want to develop an application that can be expanded through plug-ins. Therefore I created a standard library project where I want to define the plug-in interfaces. This library should then be consumed by the main application and its plug-ins.
I read about the Qt plug-in system on the official websites and sought help by duckduckgo-ing, but I'm stuck with these following errors:
vccplugin.h:16:32: error: expected parameter declarator
vccplugin.h:14:23: note: expanded from macro 'VccPlugin_iid'
vccplugin.h:16:32: error: expected ')'
vccplugin.h:14:23: note: expanded from macro 'VccPlugin_iid'
vccplugin.h:16:20: note: to match this '('
vccplugin.h:16:1: error: C++ requires a type specifier for all declarations
Build Issue: C2059: syntax error: 'string'
This is the code:
#ifndef VCCPLUGIN_H
#define VCCPLUGIN_H
#include "VccPluginInterface_global.h"
class VCCPLUGININTERFACE_EXPORT VccPlugin
{
public:
VccPlugin();
~VccPlugin();
void DoeEenTwuk();
};
#define VccPlugin_iid "automation.general.vcc.interface"
Q_DECLARE_INTERFACE(VccPlugin, VccPlugin_iid);
#endif // VCCPLUGIN_H
Also note, I have little experience in both C++ and Qt.
Any help very appreciated,
thanks
I have found the issue. The problem is that the compiler couldn't find the macro, so all I had to add was:
#include <QtPlugin>
Since Q_DECLARE_INTERFACE is defined in QtPlugin. Your example didn't import QtPlugin but was probably imported implicit by another import, probably QMainWindow.
It would have been simpler if I got an error like: "Could not find symbol Q_DECLARE_INTERFACE" if you ask me. Especially since I'm rather blue in this topic.
Thanks for your support #NgocMinhNguyen and others
I am trying to import a type library in my VC++ console application using following command.
#import "C:\typelib.tlb"
When I build the project I get following error:
Error C1196 'Request?': identifier found in type library 'C:\typelib.tlb' is not a valid C++ identifier
I haven't developed this type library but on inspection I have found that some of functions in type library are using null able parameters and I assume that's what is causing the problem e.g.
Sub ScheduleManyWithPossibleRequest(ByVal Requester As String, ByVal Request? As Boolean, ByVal SkipUnschedulableActivities? As Boolean)
Is there any way I can import this type library?
I managed to import it by using following directive with import.
#import "C:\typelib.tlb" rename("Request?", "Request")
Don't know if this would work but try doing #include instead.
Let me know if this helps, if not i'll look more into it.