Skip to content
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

Export -latomic even if BUILD_TESTING is disabled #384

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

roehling
Copy link

On some architectures, libatomic is needed and should not be dependent on tests being enabled.

Signed-off-by: Timo Röhling <roehling@debian.org>
@fujitatomoya
Copy link
Collaborator

@roehling thanks for the PR, can you explain more details why we need this and what the actual problem you have? i think that would make it easier to understand for everyone.

@roehling
Copy link
Author

The atomic operations are used by src/testing/fault_injection.c, which is compiled into the library unconditionally and may generate symbol references to libatomic on some architectures. However, as of now, the required -latomic linker flag is added only if BUILD_TESTING is enabled. This means that users may need to link against libatomic themselves, even if they do not use atomics at all, just because their rcutils library happens to be compiled with BUILD_TESTING disabled.

@fujitatomoya
Copy link
Collaborator

@roehling appreciate the explanation.

The atomic operations are used by src/testing/fault_injection.c, which is compiled into the library unconditionally and may generate symbol references to libatomic on some architectures.

is this because of the following? if that so, probably getting rid of unnecessary dependency would be solution?

#include "rcutils/testing/fault_injection.h"

and, this should be no problem, since it includes only when it is test build.

#if defined RCUTILS_ENABLE_FAULT_INJECTION
#include "rcutils/testing/fault_injection.h"

thanks,

@roehling
Copy link
Author

No, it is not.

It is because src/testing/fault_injection.c is compiled into the rcutils library here:

src/testing/fault_injection.c

And said file then uses rcutils_atomic_ operations, which in turn generate symbol references to the atomic library.

I guess, if you wanted to avoid the unconditional dependency on the atomic library, you could also make fault_injection.c conditional, for example with the generator expression $<$<BOOL:BUILD_TESTING>:src/testing/fault_injection.c>, but that means you probably should not install the corresponding headers either.

I believe my PR is less intrusive, as GCC normally adds --as-needed to the linker call, so the atomic library will only be linked if it is actually needed.

@fujitatomoya
Copy link
Collaborator

but that means you probably should not install the corresponding headers either.

yeah right, currently it include this header, e.g) /opt/ros/humble/include/rcutils/rcutils/testing/fault_injection.h

I believe my PR is less intrusive, as GCC normally adds --as-needed to the linker call, so the atomic library will only be linked if it is actually needed.

agree.

@fujitatomoya
Copy link
Collaborator

@clalancette could you take a look?

@lopsided98
Copy link

I just ran into this problem while cross-compiling to armv6, and came up with pretty much the same solution. I did find that the ament_export_link_flags("-latomic") call doesn't appear to be necessary, at least for the packages that I've built (mavros and all its dependencies, which should include all the core ROS packages).

@fujitatomoya
Copy link
Collaborator

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

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.

3 participants