-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Objective-)C++ External linkage issues for global constants in PSSpecifier.h #30
Comments
This issue is also preventing MobileGoose from compiling successfully. It was possible to compile this project without any modifications in the past. |
pixelomer
added a commit
to pixelomer/MobileGoose
that referenced
this issue
Oct 11, 2020
Fixed via #31 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Importing the PSSpecifier.h in (Objective-)c++ context gives the following errors:
Notes:
For reference, the errors shown above are while compiling HSWidgets with latest Theos. But the issue is also reproduceable when creating a new empty preference subproject and including
PSSpecifier.h
in a Objective-c++ file (.mm
).Potential Root Cause:
I think the issue is the way these global constants are defined in
PSSpecifier.h
.For C, following is the output after the pre-processor:
By default C compiler provides external linkage for all non-static global variables so this works as expected.
For c++ global constants have internal linkage by default so we need the extern "C", which is what the
__BEGIN_DECLS
is responsible for. However c++ treatsextern "C"
blocks slightly differently when it comes to variables. According to the c++ standard, this is the difference that it has:First is considered as declaration only, but second block statement is considered as a definition so the compiler needs to make sure memory will be created for b. If this were a
const
then it would require a default value. Which is the case for thePSSpecifier.h
.The way to make it not create space for the current translation unit, and ultimately not complain about the initialization, would be to either use:
or
(both of which are equivalent according to c++ standards)
The text was updated successfully, but these errors were encountered: