-
Notifications
You must be signed in to change notification settings - Fork 986
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
CMake: explicitly link the atomic library #797
Conversation
For arm & mips architecture, the linker must explicitly be asked to link the atomic library (with `-latomic`). Otherwise, the linking fails with: ``` | devel/lib/libmavros.so: undefined reference to `__atomic_load_8' | devel/lib/libmavros.so: undefined reference to `__atomic_store_8' | collect2: error: ld returned 1 exit status ``` Linking `atomic` unconditionally as library is strictly needed only for arm & mips, but it seems not to imply any further differences with other architectures. Hence, this commit simply adds `atomic` unconditionally for a uniform handling of all machine architectures. This is an alternative solution to the proposed solution in mavlink#790. The issue was discovered cross-compiling mavros in meta-ros, the OpenEmbedded layer for ROS. Some further pointers are available at: ros/meta-ros#525 Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
I think that you should link atomic to libmavconn, it's first usage and that automatically adds lib to other processes. |
@vooon I tried to address this on #790. Usage of a cmake module I don't think is required. We can check for the TARGET arch and if it is |
I've closed #790 as the complexity to find the TARGET arch on CMake wouldn't add anything beneficial to the building process. If linking the library in this general fashion would break the build, then we would have to have a condition based on the target, but that's not the case. |
I patched libmavconn and re-ran the cross-compile build tool chain on arm with this patch applied:
With this patch applied, the build of mavros (although it depends on libmavconn) continues to fail with the linking error mentioned above. Maybe, I misunderstood your suggestion to simply add the target in mavconn, but this patch does not work. libmavconn does not need atomic when it is built, but only when mavros links everything together atomic is needed for linking. I don't know CMake well enough (yet) to know a good solution to that problem. |
Yeah I also though that when the linking happened, there was not going to be an issue when building the mavros package. Maybe @vooon has something to suggest. |
Seems that atomic 32 and 64 bit are implemented (mavconn uses atomic So we may have same problem with mavconn but not on arm's. So lgtm. |
@vooon I would just like to mention here that explicitly linking atomic actually breaks the build on Mac, as Mac doesn't have an explicit libatomic to link against. I know that ROS isn't officially supported on Mac and mavros isn't either, but for the sake of general cross platform compatility it may be prudent to add a platform check before explicitly linking atomic. |
@eric1221bday that was our first approach but we ended up seeing that would be an overkill in terms of development - #790 (comment). If you have the bandwidth to develop a general approach to this, great. A PR is welcomed. |
For arm & mips architecture, the linker must explicitly be asked to link the atomic library (with
-latomic
).Otherwise, the linking fails with:
Linking
atomic
unconditionally as library is strictly needed only for arm & mips, but it seems not to imply any further differences with other architectures. Hence, this commit simply addsatomic
unconditionally for a uniform handling of all machine architectures.This is an alternative solution to the proposed solution in #790.
The issue was discovered cross-compiling mavros in meta-ros, the OpenEmbedded layer for ROS. Some further pointers are available at:
ros/meta-ros#525