androidc++qtcmakeandroid-ndk

Error building/deploying test project (build: Android Qt 6.4.2 Clang arm64-v8a)


I can't compile a C++ (Qt) project for Android. The project is being compiled under Linux, but when I compiled my library under arm64-v8a, and then compiled the project, qt gives an error:

error: undefined symbol: __sendto_chk
referenced by socket.h:72 (/home/misha/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/fortify/socket.h:72)
connect.cpp.o:(OBD::OBDConnectNetwork::sendAllData()) in archive /usr/local/lib/libobd_scanner.a
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

I use system calls in my library.

When I include the library header the project builds correctly but when I create the object the project doesn't build

Here are the CMakeLists:

cmake_minimum_required(VERSION 3.5)

project(obd_scanner_qt VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(obd_scanner STATIC IMPORTED)
set_target_properties(obd_scanner PROPERTIES IMPORTED_LOCATION /usr/local/lib/libobd_scanner.a)
include_directories(/usr/local/include/obd_scanner)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
#find_package(obd_scanner REQUIRED)

set(PROJECT_SOURCES
        src/main.cpp
        src/mainwindow.cpp
        src/mainwindow.h
        src/mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(obd_scanner_qt
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
else()
    if(ANDROID)
        add_library(obd_scanner_qt SHARED
            ${PROJECT_SOURCES}
        )
    else()
        add_executable(obd_scanner_qt
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(obd_scanner_qt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(obd_scanner_qt PRIVATE obd_scanner)

set_target_properties(obd_scanner_qt PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)
target_compile_options(obd_scanner_qt PRIVATE -Wall)

install(TARGETS obd_scanner_qt
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(obd_scanner_qt)
endif()

When I call find_package(), it says that the library was not found, but there is no such problem under the Linux assembly

I created a test library without system calls, then everything works

I will be grateful for any answer


Solution

  • I was finally able to solve my problem. The problem was that I was compiling my library on NDK version 25.1.8937393. When I compiled the library on NDK version 23.1.7779620 everything worked

    cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/misha/Android/Sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_NATIVE_API_LEVEL=29