ARMv8.1 Chromebook的Termux编译Taskwarrior 2.5.1遇__atomic_fetch_add_4未定义引用
__atomic_fetch_add_4 Undefined Reference When Compiling task-2.5.1 on ARMv8.1 Chromebook (Termux) The issue you're hitting is common on ARM targets when using libc++ (which you're specifying with -stdlib=libc++): the atomic operations used in Nibbler.cpp require linking against the libatomic library, and CMake isn't adding this dependency automatically. Manually editing link.txt doesn't work because CMake regenerates that file every time you run make, overwriting your changes. Here's how to fix it properly:
Solution 1: Modify the Project's CMakeLists.txt
This is the most reliable approach, as it embeds the dependency directly into the build configuration:
- Navigate to the
srcdirectory of your task-2.5.1 source tree:cd /data/data/com.termux/files/home/src/task-2.5.1/src - Open the
CMakeLists.txtfile (the one defining thelex_executabletarget) in a text editor likenano. - Locate the
target_link_librariessection forlex_executable. It should resemble this:target_link_libraries(lex_executable libtask.a commands/libcommands.a columns/libcolumns.a libtask.a gnutls uuid ) - Add
atomicto the end of the list to explicitly link against libatomic:target_link_libraries(lex_executable libtask.a commands/libcommands.a columns/libcolumns.a libtask.a gnutls uuid atomic ) - Save the file, then re-run CMake to regenerate build files:
cd .. cmake . - Re-run
make VERBOSE=1—you should see-latomicincluded in the linker command, and the undefined reference errors should resolve.
Solution 2: Pass Linker Flags Directly to CMake
If you prefer not to modify the project's CMake files, specify the linker flag when initializing the build:
- Clean your existing build directory (optional but recommended to avoid stale files):
cd /data/data/com.termux/files/home/src/task-2.5.1 make clean rm CMakeCache.txt - Re-run CMake with the
CMAKE_EXE_LINKER_FLAGSparameter set to include-latomic:cmake -DCMAKE_EXE_LINKER_FLAGS="-latomic" . - Proceed with compiling as before:
make VERBOSE=1
Why This Works
On ARM platforms, libc++ doesn't link against libatomic by default, even though it's required for certain atomic operations like __atomic_fetch_add_4. By explicitly adding the atomic library to the linker dependencies—either via CMakeLists.txt or command-line flags—you're telling the linker to include the necessary atomic operation implementations.
内容的提问来源于stack exchange,提问作者Grant Bowman

