-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Link error for identifier FirstTime
#2
Comments
All that said, given that the name is only referred to in |
Never mind, LRSLib.jl does want to modify the value of |
Thanks for investigating this and detailing your reasoning so precisely here. Another fix could be to add add an include guard. Otherwise, yes indeed I think if the variable is in the |
The error happens at link-time because the symbol is defined in two different object files, an include guard would be useless
|
@giordano, AFAICS, the declaration/definition in |
One option is to update to the latest The declaration is removed from (EDIT: Maybe we need a definition in |
@oyamad yes, I think we need either to keep the variable extern or expose a |
All for updating to latest upstream lrslib too, but yeah it might be more effort than we have available right now. |
In CI here, clang complained of a double definition.
This looks like a valid complaint to me, though as we saw here, gcc successfully compiles the same code. Presumably this means the code is incorrect (i.e. compiler behavior is unspecified) but gcc is being lenient in some way.
Quoting @giordano:
I've personally never seen an issue like this before, for (I think) two reasons: (1) I've never seen a non-
static
, non-extern
global variable in a header file; (2) all the codebases I've worked in have had include guards on the header files, so re-declaration was not happening.What we need to do
We should fix the link error in a way that does not change program behavior.
As far as I can see, the only sane way this program would compile is if the offending line is being treated as an
extern
declaration. However I don't have iron-clad proof of this, and I think it's a statement about the behavior of GCC that is not mandated by the C standard.Of course, we could also start reasoning about the program itself and what it's supposed to do, and/or contact the author 🙂
Attempting to get a full explanation
According to Wikipedia:
According to cppreference
Sadly, the above quote does not explicitly say whether the statement
with no storage-class specifier and no initialization must be considered a definition, or must be considered only a declaration, or whether it's up to the toolchain. (Wikipedia apparently says it's up to the toolchain.)
As far as I can tell, this line is getting inlined twice by the preprocessor (since there is no include guard), and the clang error above seems to indicate that clang is considering at least two of the copies of that line to be definitions (since the only other use of that name in the codebase is definitely neither a definition nor a declaration). Perhaps gcc chooses not to consider more than one of those copies a definition.
On the other hand, if all copies of that line are considered to be declarations and not definitions, then the following excerpt from cppreference:
implies that the line is equivalent to
The text was updated successfully, but these errors were encountered: