坦白说,我在智慧的结尾,我真的需要一个地方崩溃。编译时,我一直在收到一个
error: linker command failed with exit code 1 (use -v to see invocation)
我认为这是由于项目构建和boost库之间的不兼容或简单不同的编译器版本,但只要我阅读二进制文件是完美兼容的(?)。
建设提升
我在Windows 10上通过MinGW进行编译,但为了排除错误,我最终使用this git shell script来构建boost,它使用最新版本的Boost(1.64.0)和NDK(r15b)。我是在Ubuntu 16.04的VirtualBox中完成的,因为我没有足够的知识来适应Windows 10(至少我没有办法)。现在我已经使用gnu-4.9和llvm-3.5 for x86编译了分片和静态库(我的AStudio中的模拟器也已加入)。
Android Studio
我正在使用Cmake来构建我的项目的C / C++库。我有几个C库和一个相互依赖的C++库。最后一个是使用boost的。由于所有的库都是在没有错误的情况下构建和发现的,所以对于我来说这似乎是一个名称问题,尽管所有的C头文件都有预处理器声明:extern C.除了boost部分,所有运行都完美无缺
CMake的结果
find_package()REQUIRED参数已设置,并且Boost_DEBUG指示已找到所有组件。由于在某个时候我得到了错误
undefined reference to boost::system::generic_category()
我将系统添加到组件中,所以我的简约组件设置仅包含chrono和系统,就像关于此特定问题的许多其他线程所建议的那样。我试图单独链接boost库,但没有成功:
target_link_libraries( MyLib ${Boost_SYSTEM_LIBRARY}
${Boost_CHRONO_LIBRARY}
)但是现在我遇到了上述问题,在这一点上,我悬挂着休战旗帜。非常感谢每一个提示!非常感谢您提前!
的CMakeLists.txt
set( Boost_DEBUG ON )
set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_STATIC_RUNTIME ON )
set( Boost_USE_MULTITHREADED OFF )
set( Boost_NO_SYSTEM_PATHS ON )
set( BOOST_ALL_DYN_LINK OFF )
set( BOOST_ROOT C:/MyBoost )
set( Boost_INCLUDE_DIR ${BOOST_ROOT}/include )
set( Boost_LIBRARY_DIR ${BOOST_ROOT}/lib )
set( Boost_Version 1.64.0 )
find_package( Boost ${Boost_Version} COMPONENTS system chrono )
if( Boost_FOUND )
target_include_directories( MyLib PUBLIC/PRIVATE ${Boost_INCLUDE_DIR} )
link_directories( ${Boost_LIBRARY_DIR} )
endif()
target_link_libraries( MyLib ${Boost_LIBRARIES} )的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "My_ID"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
=====更新===== h2>
我补充说
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions -DBOOST_SYSTEM_NO_DEPRECATED"
}到build.gradle文件,现在它按预期编译,甚至包括线程或计时库!尽管我之前分解的一些命令现在还没有工作。我现在正在跟踪错误:
libboost_chrono.a: error adding symbols: File in wrong format
这应该是apk版本和boost libs的问题!如何确保我使用正确的Boost版本?