Reputation: 1
Im trying to build mysql-connector-cpp from git to use at Android arm to connector mysql Server
im trying to compile by
mkdir build
cmake .. \
-DCMAKE_C_COMPILER=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/clang \
-DCMAKE_CXX_COMPILER=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang++ \
-DCMAKE_C_FLAGS="-I/home/ripper/android-ndk/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" \
-DCMAKE_CXX_FLAGS="-I/home/ripper/android-ndk/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" \
-DANDROID_ABI=x86_64 \
-DANDROID_PLATFORM=android-34 \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=/home/ripper/sources_pck/android_libs/mysql-connector-cpp \
-DWITH_SSL=/home/ripper/sources_pck/android_libs/openssl-3.4.0-android/lib/libssl \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_UNIT_TESTS=OFF \
-DWITH_EXAMPLES=OFF \
-DWITH_JDBC=OFF
and after run make
== Extrnal build done
[ 2%] Built target zstd-build
[ 4%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/error.cc.o
[ 5%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/stream.cc.o
[ 6%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/connection_tcpip.cc.o
[ 8%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/socket.cc.o
[ 9%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/diagnostics.cc.o
[ 10%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o
/home/ripper/sources_pck/mysqlcpp/mysql-connector-cpp/cdk/foundation/socket_detail.cc:1097:22: error: variable has incomplete type 'struct __res_state'
1097 | struct __res_state state {};
| ^
/home/ripper/sources_pck/mysqlcpp/mysql-connector-cpp/cdk/foundation/socket_detail.cc:1097:10: note: forward declaration of '__res_state'
1097 | struct __res_state state {};
| ^
1 error generated.
make[2]: *** [cdk/foundation/CMakeFiles/cdk_foundation.dir/build.make:149: cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o] Помилка 1
make[1]: *** [CMakeFiles/Makefile2:1055: cdk/foundation/CMakeFiles/cdk_foundation.dir/all] Помилка 2
make: *** [Makefile:136: all] Помилка 2
at first stage i need to build it for using to android emulation x86_64
like that way I've already buld OpenSSL and Curl libs and boost lib I've tryed OpenSSL and Curl thay at least can resolv lib version doesnt test deep.
I've little bit edit source and now i have issue with compiling lib with protoc i've already precompile lib ... but i cant just add it to project it ask for runnable ... /usr/protobuf-android-x86_64/bin/protoc-30.0.0: error while loading shared libraries: /lib/x86_64-linux-gnu/libm.so: invalid ELF header - its precompiled
ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, with debug_info, not stripped
[1%] Building CXX object CMakeFiles/save_linker_opts.dir/cmake/libutils/save_linker_opts.cc.o
[ 2%] Linking CXX executable libutils/save_linker_opts
[ 2%] Built target save_linker_opts
[ 4%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/error.cc.o
[ 5%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/stream.cc.o
[ 6%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/connection_tcpip.cc.o
[ 8%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/socket.cc.o
[ 9%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/diagnostics.cc.o
[ 10%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o
[ 12%] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/connection_openssl.cc.o
[ 13%] Linking CXX static library libcdk_foundation.a
[ 13%] Built target cdk_foundation
[ 15%] Preparing protobuf files for protobuf-lite
[ 16%] Running C++ protocol buffer compiler on /home/ripper/sources_pck/mysql-connector-c++-9.1.0-src/build/cdk/protocol/mysqlx/lite/mysqlx_sql.proto
/bin/sh: 1: /home/ripper/sources_pck/android_libs/protobuf-android-x86_64/bin/protoc: not found
make[2]: *** [cdk/protocol/mysqlx/CMakeFiles/cdk_proto_mysqlx.dir/build.make:155: cdk/protocol/mysqlx/protobuf/mysqlx_sql.pb.cc] ERROR 127
make[1]: *** [CMakeFiles/Makefile2:1063: cdk/protocol/mysqlx/CMakeFiles/cdk_proto_mysqlx.dir/all] ERROR 2
make: *** [Makefile:136: all] ERROR 2
Upvotes: -1
Views: 46
Reputation: 2438
The MySql-Connector-Cpp is not a cross-compile friendly library, and it does not support Android out-of the box. To compile it, you will have no choice than to patch the source code and the cmake scripts.
The Cmake files start a bootstrap procedure that overwrites the C_COMPILER and CXX_COMPILER passed through the android toolchain file, the easiest way to bypass that is to use ninja build system (the bootstrap is skipped in that case). Moreover, the Cmake files use heavily the function execute_process, which is used to start other cmake sessions to compile the dependency library. Each spawned session does not inherit the command line parameters from the spawner, and it's needed to add this propagation on the Cmake files.
The compilation process uses two tools, protoc and save_linker_opts. These two tools need to be compiled for the host environment and then used to compile for the target environment.
Add an Android compatible function in socket_detail.cc that is equivalent to the one using res_nsearch, but uses android NDK API.
remove the resolv library from linked libraries and add the android one, and disabling BMI2 in case of x86_64 architectures for zstd library.
A fully automated build can be found at https://github.com/AndrewBloom/connector-cpp-android The build generates the artifacts but was not tested in a real scenario, Nonetheless it should give a good indication of the steps needed to cross-compile mysql-connector-cpp. It is intended as proof-of-concept, while a cleaner solution would imply a full rewrite of all CMake files.
Upvotes: 0