How can I solve pthread & posix error when building C++ for Android with CMake

445 views Asked by At

I have a big problem with a project of mine. In a view words: I want to port the programming language ooRexx to Android. ooRexx is written mostly in C++

I have the NDK installed and so far everything works fine.

First of all I run CMake with this command: cmake -DCMAKE_TOOLCHAIN_FILE=~/coding/android-ndk-r22b/build/cmake/android.toolchain.cmake -DANDROID_ABI="x86" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DANDROID_NATIVE_API_LEVEL=22

there are a view warnings but overall it works. but some warnings are related to my problem so i will post them:

-- Performing Test HAVE_PTHREAD_MUTEX_ERRORCHECK
-- Performing Test HAVE_PTHREAD_MUTEX_ERRORCHECK - Failed
-- Performing Test HAVE_PTHREAD_MUTEX_RECURSIVE
-- Performing Test HAVE_PTHREAD_MUTEX_RECURSIVE - Failed

Next I want to build the whole thing with cmake --build ./

And now there are 2 possible outcomes depending on what Im using in the CMakelists.txt When I leave the CMakeLists.txt as it is theres the following line: set (platform_rexxapi_libs ${ORX_SYSLIB_DL} ${ORX_SYSLIB_PTHREAD})

This line throws the following error: couldnt find -lpthread and the whole build process stops at 13% with this error.

In my research I read that its not necessary to define pthread explicitly when building for Android. So Im removing ${ORX_SYSLIB_PTHREAD} So far so good. Thats helps a bit. The build process goes up to 72% and then stops with posix errors. I get the following errors:

/home/tjk/coding/oorexx/oorexxsvn/main/trunk/interpreter/platform/unix/SystemCommands.cpp:1022:17: error: use of undeclared identifier 'posix_spawnp'
            if (posix_spawnp(&pid, argv[0], NULL, NULL, argv, getEnvironment()) != 0)
                ^
11 errors generated.
make[2]: *** [CMakeFiles/rexx.dir/build.make:2806: CMakeFiles/rexx.dir/interpreter/platform/unix/SystemCommands.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:647: CMakeFiles/rexx.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

i checked and sthe spawn.h library is in the file. Additionally these error will not show up when building for Linux or Windows. So the problem must be related to the Android Toolchain and the CMakeLists.txt

A former colleague already made a working build for Android a few zears ago. But its poorly documented. However he faced the same problem and found out that there needs to be some additional infos in the CMakeLists.txt file.

The additional code should be:

if (ANDROID)
   add_definitions(-DHAVE_PTHREAD_MUTEXATTR_SETTYPE)
   add_definitions(-DHAVE_PTHREAD_MUTEX_RECURSIVE)
endif ()

I added this in the file but it makes no difference. I get the same error at 72%.

Anyone has an idea where the problem is located? Am I providing enough info? Please tell me if I dont. By now its probably obvious that I dont have much experience with CMake, Android. So if additional Info is needed please be so kind and tell me. Ill provide.

Thanks for your help. It is much appreciated.

Best Thomas

0

There are 0 answers