cmake 生成/部署测试项目时出错(生成:安卓Qt 6.4.2 Clang arm 64-v8 a)

f87krz0w  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(283)

我无法为Android编译C++(Qt)项目。这个项目是在Linux下编译的,但是当我在arm 64-v8 a下编译我的库,然后编译这个项目时,qt给出了一个错误:

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.

我在库中使用系统调用。
当我包含库头时,项目将正确构建,但当我创建对象时,项目将无法构建
以下是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()

当我调用find_package()时,它说没有找到库,但是在Linux程序集下没有这样的问题
我创建了一个没有系统调用的测试库,然后一切正常
如有任何答复,我将不胜感激

zfciruhq

zfciruhq1#

我终于解决了我的问题。问题是我在NDK版本25.1.8937393上编译我的库。当我在NDK版本23.1.7779620上编译库时,一切正常

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

相关问题