AARCH64 tensorflow lite build problem

I’ve an ARM64 that I need to build tensorflow lite, and I’m using cmake. The cmake command fails when the pthread test code doesn’t build. The test code is:

#include <pthread.h>

void* test_func(void* data)
{
return data;
}

int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);

return 0;
}

I build the test code manually with the following command, and it builds and runs.

cc src.c -lpthread

What is the cmake looking for that would cause this build to fail? I have LD_LIBRARY_PATH set to where the pthread library/so is. The cmake error output file is as follows. Why doesn’t the link command have -lpthread? Thank you.

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/xilinx/tflite_build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_84682/fast && /usr/bin/make -f CMakeFiles/cmTC_84682.dir/build.make CMakeFiles/cmTC_84682.dir/build
make[1]: Entering directory ‘/home/xilinx/tflite_build/CMakeFiles/CMakeTmp’
Building C object CMakeFiles/cmTC_84682.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -fPIE -o CMakeFiles/cmTC_84682.dir/src.c.o -c /home/xilinx/tflite_build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_84682
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_84682.dir/link.txt --verbose=1
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD CMakeFiles/cmTC_84682.dir/src.c.o -o cmTC_84682
/usr/bin/ld: CMakeFiles/cmTC_84682.dir/src.c.o: in function main': src.c:(.text+0x48): undefined reference to pthread_create’
/usr/bin/ld: src.c:(.text+0x50): undefined reference to pthread_detach' /usr/bin/ld: src.c:(.text+0x5c): undefined reference to pthread_join’
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_84682.dir/build.make:87: cmTC_84682] Error 1
make[1]: Leaving directory ‘/home/xilinx/tflite_build/CMakeFiles/CMakeTmp’
make: *** [Makefile:121: cmTC_84682/fast] Error 2

Source file was:
#include <pthread.h>

void* test_func(void* data)
{
return data;
}

int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);

return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/xilinx/tflite_build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_a7f5d/fast && /usr/bin/make -f CMakeFiles/cmTC_a7f5d.dir/build.make CMakeFiles/cmTC_a7f5d.dir/build
make[1]: Entering directory ‘/home/xilinx/tflite_build/CMakeFiles/CMakeTmp’
Building C object CMakeFiles/cmTC_a7f5d.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -fPIE -o CMakeFiles/cmTC_a7f5d.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_a7f5d
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a7f5d.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_a7f5d.dir/CheckFunctionExists.c.o -o cmTC_a7f5d -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_a7f5d.dir/build.make:87: cmTC_a7f5d] Error 1
make[1]: Leaving directory ‘/home/xilinx/tflite_build/CMakeFiles/CMakeTmp’
make: *** [Makefile:121: cmTC_a7f5d/fast] Error 2

Hi, @rambo2_981

I apologize for the delayed response, I believe you’re following below steps, if not could you please give it try with below mentioned steps and see are you able to build successfully or not? please refer this official documentation

!sudo apt-get install cmake
!git clone https://github.com/tensorflow/tensorflow.git tensorflow_src

!curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz

!mkdir -p toolchains

!tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C toolchains

!ARMCC_PREFIX=toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
!ARMCC_FLAGS="-funsafe-math-optimizations"

!cmake -DCMAKE_C_COMPILER=/content/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc \
  -DCMAKE_CXX_COMPILER=/content/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ \
  -DCMAKE_C_FLAGS="-funsafe-math-optimizations" \
  -DCMAKE_CXX_FLAGS="-funsafe-math-optimizations" \
  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_PROCESSOR=aarch64 \
  tensorflow_src/tensorflow/lite/

!cmake --build . -j 4

If issue still persists please let us know with updated error log to investigate this issue further.

Thank you for your cooperation and patience.