Skip to content

-latomic not added autmatically when using GCC on ARM (Raspberry Pi 4, Raspbian 32-bit)

Originally reported in https://github.com/arvidn/libtorrent/issues/5117#issue-695875535.

Basically, -latomic is not being added when it should, resulting in linking failures like the following:

[160/179] Linking CXX executable tools/session_log_alerts                                                                                                                                                                                                                
FAILED: tools/session_log_alerts                                                                                                                                                                                                                                 
: && /usr/bin/c++ -O3 -DNDEBUG  tools/CMakeFiles/session_log_alerts.dir/session_log_alerts.cpp.o -o tools/session_log_alerts  -Wl,-rpath,/home/pi/libtorrent/cmake-build-dir:/opt/boost-1.74.0/lib  libtorrent-rasterbar.so.1.2.10  -lpthread  
/usr/lib/arm-linux-gnueabihf/libssl.so  /usr/lib/arm-linux-gnueabihf/libcrypto.so  /opt/boost-1.74.0/lib/libboost_system.so.1.74.0 && :                                                                                                                                  
/usr/bin/ld: libtorrent-rasterbar.so.1.2.10: undefined reference to `__atomic_compare_exchange_8'                                                                                                                                                                        
/usr/bin/ld: libtorrent-rasterbar.so.1.2.10: undefined reference to `__atomic_load_8'                                                                                                                                                                                    
/usr/bin/ld: libtorrent-rasterbar.so.1.2.10: undefined reference to `__atomic_store_8'                                                                                                                                 
/usr/bin/ld: libtorrent-rasterbar.so.1.2.10: undefined reference to `__atomic_fetch_add_8'                                                                                                                            
collect2: error: ld returned 1 exit status

This seems to be a very prevalent problem. Here are some ways other projects that have run into this have solved the problem: https://github.com/pothosware/SoapyRTLSDR/pull/42 https://github.com/opencv/opencv/pull/15353

Patching in something like target_link_libraries(tgt PRIVATE atomic) in the CML or passing -DCMAKE_EXE_LINKER_FLAGS="-latomic", or using clang (9.0.1) instead of instead of GCC (8.3.0), can all be used to workaround this as well.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information