неопределенная ссылка на `boost :: filesystem :: detail :: create_directory - PullRequest
0 голосов
/ 05 октября 2019

Я пытаюсь использовать boost 1.68 (64-битный, сборка с использованием clang) с одним из наших 64-битных приложений для Android. У меня проблемы с линковкой boost :: filesystem.

Я попробовал почти все, что было предложено в Stackoverflow. Например, я попробовал следующее

#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#undef BOOST_NO_CXX11_SCOPED_ENUMS

, но ни один из них не работает для меня.

Вот мой код cpp

boost::filesystem::path path = GetLaunchPath();
boost::filesystem::path p(path);
boost::filesystem::create_directory(p);

Вот вывод команды сборки ...

[2/2] Linking CXX shared library /XXXX/product/HelloJNI/app/build/intermediates/cmake/arm8/debug/obj/arm64-v8a/libhello-jni.so
FAILED: /XXXX/product/HelloJNI/app/build/intermediates/cmake/arm8/debug/obj/arm64-v8a/libhello-jni.so 
: && /XXXX/Library/Android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ 
--target=aarch64-none-linux-android23 
--gcc-toolchain=/XXXX/Library/Android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64 
--sysroot=/XXXX/Library/Android/sdk/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/sysroot 
-fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong 
-no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ 
-DBOOST_ERROR_CODE_HEADER_ONLY 
-DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS -O0 -fno-limit-debug-info  
-Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,
--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack 
-Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libhello-jni.so -o /XXXX/product/HelloJNI/app/build/intermediates/cmake/arm8/debug/obj/arm64-v8a/libhello-jni.so 
CMakeFiles/hello-jni.dir/hello-jni.cpp.o  -landroid -llog 
/XXXX/Downloads/openssl_for_ios_and_android-master/tools/openssl-1.0.2t/libcrypto.a 
/XXXX/Downloads/openssl_for_ios_and_android-master/tools/openssl-1.0.2t/libssl.a 
/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/lib/libboost_thread-clang-darwin-mt-a64-1_68.a 

#/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/lib/libboost_filesystem-clang-darwin-mt-a64-1_68.a

/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/lib/libboost_system-clang-darwin-mt-a64-1_68.a
/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/lib/libboost_chrono-clang-darwin-mt-a64-1_68.a
/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/lib/libboost_date_time-clang-darwin-mt-a64-1_68.a
/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/lib/libboost_atomic-clang-darwin-mt-a64-1_68.a 
-latomic -lm && :
CMakeFiles/hello-jni.dir/hello-jni.cpp.o: In function `boost::filesystem::create_directory(boost::filesystem::path const&)':
/XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a/include/boost-1_68/boost/filesystem/operations.hpp:572: 
#undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Файл Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId 'com.example.hellojni'
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        externalNativeBuild{
            cmake {
                version "3.15.3"
                abiFilters.addAll([ 'arm64-v8a'])
                cppFlags.addAll([
                        '-DBOOST_ERROR_CODE_HEADER_ONLY',
                        '-DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS',
                ])
                arguments "-DANDROID_TOOLCHAIN=clang"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            version "3.15.3"
            path "src/main/cpp/CMakeLists.txt"
        }
    }

    flavorDimensions 'cpuArch'
    productFlavors {
        arm7 {
            dimension 'cpuArch'
            ndk {
                abiFilter 'armeabi-v7a'
            }
        }
        arm8 {
            dimension 'cpuArch'
            ndk {
                abiFilters 'arm64-v8a'
            }
        }
        x86 {
            dimension 'cpuArch'
            ndk {
                abiFilter 'x86'
            }
        }
        x86_64 {
            dimension 'cpuArch'
            ndk {
                abiFilter 'x86_64'
            }
        }
        universal {
            dimension 'cpuArch'
            // include all default ABIs. with NDK-r16,  it is:
            //   armeabi-v7a, arm64-v8a, x86, x86_64
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15.3)
set (OPENSSL_PATH /XXXX/Downloads/openssl_for_ios_and_android-master/tools/openssl-1.0.2t)
set (BOOST_PATH /XXXX/Downloads/Boost-for-Android-master/build/out/arm64-v8a)

set(Boost_USE_STATIC_LIBS        ON)  # only find static libs
set(Boost_USE_DEBUG_LIBS         OFF) # ignore debug libs and
set(Boost_USE_RELEASE_LIBS       ON)  # only find release libs
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
set(Boost_NO_SYSTEM_PATHS ON)
set(BOOST_ROOT "${BOOST_PATH}")
set(Boost_INCLUDE_DIR "${BOOST_PATH}/include/boost-1_68")
set(Boost_LIBRARY_DIR "${BOOST_PATH}/lib")
set(Boost_COMPILER -clang-darwin)
set(Boost_ADDITIONAL_VERSIONS "1.68")
set(Boost_THREADAPI "pthread")
set(Boost_ARCHITECTURE "-a64")
set(Boost_DEBUG 1)

find_package(Boost REQUIRED thread filesystem system) #ldLibs.addAll(['boost_chrono-gcc-mt-1_60', 'boost_thread_pthread-gcc-mt-1_60', 'boost_system-gcc-mt-1_60', 'boost_filesystem-gcc-mt-1_60'])

add_library(hello-jni SHARED
        hello-jni.cpp)


if(Boost_FOUND)
    message("Found BOOST")

    ADD_DEFINITIONS( "-DHAS_BOOST" )
    SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${BOOST_PATH}/lib)
    link_directories(${Boost_LIBRARY_DIR})
else()
    message("********BOOST not found**********")

endif()

# Include libraries needed for hello-jni lib
#include_directories(/XXXX/Downloads/openssl_for_ios_and_android-master/tools/openssl-1.0.2t/include ${BOOST_PATH}/include)
include_directories(/XXXX/Downloads/openssl_for_ios_and_android-master/tools/openssl-1.0.2t/include ${BOOST_PATH}/include/boost-1_68)
target_link_libraries(hello-jni
                      android
                      log
        ${OPENSSL_PATH}/libcrypto.a
        ${OPENSSL_PATH}/libssl.a
        ${Boost_LIBRARIES})
...