Skip to content

Conversation

@JJL772
Copy link
Contributor

@JJL772 JJL772 commented Oct 18, 2023

Fixes some issues I ran into when building this locally.

Closes #30

Copy link
Collaborator

@marciodo marciodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using extern in variables inside header files doesn't seem right to me. Can you comment more on it? Maybe add the compiler message error that you are getting without it?

@JJL772
Copy link
Contributor Author

JJL772 commented Nov 23, 2023

The IOC specifically fails to build with linker errors. This is due to how static libraries are generated; each translation unit that includes a header containing a variable definition without external or static linkage (i.e. int test;) will get a globally visible definition. When the linker assembles them, it sees more than one symbol with the name and gets upset.

image

@JJL772
Copy link
Contributor Author

JJL772 commented Nov 27, 2023

This is actually a symptom of -fcommon and -fno-common. It links fine if you force the compiler to emit everything into the same data/bss section with -fcommon. GCC docs say -fno-common is the default though: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fcommon

The -fcommon places uninitialized global variables in a common block. This allows the linker to resolve all tentative definitions of the same variable in different compilation units to the same object, or to a non-tentative definition. This behavior is inconsistent with C++, and on many targets implies a speed and code size penalty on global variable references. It is mainly useful to enable legacy code to link without errors.

The default probably changed since GCC 4.8.5.

@JJL772 JJL772 requested a review from marciodo April 9, 2024 23:54
@gustavosr8
Copy link
Contributor

The IOC specifically fails to build with linker errors. This is due to how static libraries are generated; each translation unit that includes a header containing a variable definition without external or static linkage (i.e. int test;) will get a globally visible definition. When the linker assembles them, it sees more than one symbol with the name and gets upset.

image

I've been through the same problems and it worked fine with the changes in @JJL772's branch.

@marciodo marciodo changed the base branch from master to pre-release July 6, 2024 18:36
Copy link
Collaborator

@marciodo marciodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run in the test environment and it worked.

@marciodo marciodo merged commit 07f712d into slac-epics-modules:pre-release Jul 17, 2024
@JJL772 JJL772 deleted the misc-things branch July 17, 2024 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multiple definition errors when building with C++20

3 participants