Wednesday, September 5, 2018

android load native dll dlopen failed . Undefined Reference to __atomic_* . __atomic_exchange_4

reference to: https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md

Some ABIs (particularly armeabi) need libatomic to provide some implementations for atomic operations.

The case was arm64 works,  armeabi had exception . 
dlopen failed,  Undefined Reference to __atomic_exchange_4

Solution: Add -latomic when linking.

The solution not working, since the -latomic already in link flag.

reference to :

https://github.com/android-ndk/ndk/issues/589

Just FYI, we were running into the same issue. In our case it was not enough to add -latomic to the linker option, but -latomic had to be listed as the last option, even after the C++ standard library.

So the added -Wl -latomic fix the issue.