我正在尝试使用NDK 9C在Android上构建Boost 1.55 Log v2库。 我已经使用了补丁并使用build-android.sh构建了boost,包括线程,iostreams,随机和日志选项。 我已经使用了Boost的其他功能,他们已经工作了。但似乎存在与Log V2的链接问题,我无法用现有解决方案解决。我一直得到相同的“未定义引用”错误。 在网络上,人们解决了这个问题,包括“#define BOOST_ALL_DYN_LINK”,但它对我不起作用。你知道可能是什么问题吗?提前谢谢。
控制台输出:
10:35:45 **** Build of configuration Default for project BoostLogLib ****
/home/guven/Desktop/IDP/adt/android-ndk-r9c/ndk-build all
Android NDK: WARNING: APP_PLATFORM android-9 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
Android NDK: WARNING:jni/Android.mk:BoostLogLib: non-system libraries in linker flags: /home/guven/Desktop/IDP/adt/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a -lboost_system-gcc-mt-1_55 -lboost_filesystem-gcc-mt-1_55 -lboost_thread-gcc-mt-1_55 -lboost_iostreams-gcc-mt-1_55 -lboost_date_time-gcc-mt-1_55 -lboost_random-gcc-mt-1_55 -lboost_log-gcc-mt-1_55 -lboost_log_setup-gcc-mt-1_55 -lboost_program_options-gcc-mt-1_55 -lboost_regex-gcc-mt-1_55 -lboost_chrono-gcc-mt-1_55
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
[armeabi-v7a] Compile++ thumb: BoostLogLib <= BoostLogLib.cpp
[armeabi-v7a] SharedLibrary : libBoostLogLib.so
jni/BoostLogLib.cpp:20: error: undefined reference to 'boost::log::v2_mt_posix::core::get()'
/home/guven/Desktop/IDP/workspace/3rdparty/Boost-for-Android/boost_1_55_0/boost/log/attributes/attribute_name.hpp:80: error: undefined reference to 'boost::log::v2_mt_posix::attribute_name::get_id_from_string(char const*)'
jni/BoostLogLib.cpp:20: error: undefined reference to 'boost::log::v2_mt_posix::core::set_filter(boost::log::v2_mt_posix::filter const&)'
/home/guven/Desktop/IDP/workspace/3rdparty/Boost-for-Android/boost_1_55_0/boost/log/attributes/value_extraction.hpp:232: error: undefined reference to 'boost::log::v2_mt_posix::attribute_value_set::find(boost::log::v2_mt_posix::attribute_name) const'
/home/guven/Desktop/IDP/workspace/3rdparty/Boost-for-Android/boost_1_55_0/boost/log/attributes/value_extraction.hpp:233: error: undefined reference to 'boost::log::v2_mt_posix::attribute_value_set::end() const'
/home/guven/Desktop/IDP/workspace/3rdparty/Boost-for-Android/boost_1_55_0/boost/log/attributes/value_extraction.hpp:241: error: undefined reference to 'boost::log::v2_mt_posix::aux::attach_attribute_name_info(boost::exception&, boost::log::v2_mt_posix::attribute_name const&)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libBoostLogLib.so] Error 1
10:35:50 Build Finished (took 4s.138ms)
示例“helloworld”项目代码如下。 BoostLogLib.h文件
#ifndef BOOSTLOGLIB_H_
#define BOOSTLOGLIB_H_
#include <jni.h>
#include <iostream>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: print
* Signature: ()V
*/
JNIEXPORT jstring JNICALL Java_com_example_boostloglib_BoostLogLib_print
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif /* BOOSTLOGLIB_H_ */
BoostLogLib.cpp文件
#define BOOST_LOG_USE_CHAR
#define BOOST_ALL_DYN_LINK
#include "BoostLogLib.h"
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
namespace logging = boost::log;
//[ example_tutorial_trivial_with_filtering
void init()
{
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
}
int start_logging()
{
init();
return 0;
}
JNIEXPORT jstring JNICALL Java_com_example_boostloglib_BoostLogLib_print(JNIEnv * env, jobject obj){
start_logging();
jstring result = env->NewStringUTF("Hello world!!!"); // C style string to Java String
return result;
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := BoostLogLib
LOCAL_SRC_FILES := BoostLogLib.cpp
LOCAL_CPP_EXTENSION := .cpp
LOCAL_CPPFLAGS += -std=c++0x
LOCAL_LDLIBS += $(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libgnustl_static.a
LOCAL_CFLAGS += -lpthread
LOCAL_CFLAGS += -I$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include
LOCAL_CFLAGS += -I$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include
LOCAL_CFLAGS += -I/home/guven/Desktop/IDP/workspace/3rdparty/Boost-for-Android/boost_1_55_0
LOCAL_LDLIBS += -L/home/guven/Desktop/IDP/workspace/3rdparty/Boost-for-Android/build/lib -lboost_system-gcc-mt-1_55 -lboost_filesystem-gcc-mt-1_55 -lboost_thread-gcc-mt-1_55 -lboost_iostreams-gcc-mt-1_55 -lboost_date_time-gcc-mt-1_55 -lboost_random-gcc-mt-1_55 -lboost_log-gcc-mt-1_55 -lboost_log_setup-gcc-mt-1_55 -lboost_program_options-gcc-mt-1_55 -lboost_regex-gcc-mt-1_55 -lboost_chrono-gcc-mt-1_55
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_MODULES := BoostLogLib
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_PLATFORM := android-9
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS += -std=c++0x
答案 0 :(得分:0)
似乎问题是由于静态库链接引起的 问题是它寻找这样的符号:
boost::log::v2_mt_posix::core::set_filter
但相反,图书馆有符号:
boost::log::v2s_mt_posix::core::set_filter
如果删除了#define BOOST_ALL_DYN_LINK,则将Application.mk中的APP_STL从gnustl_static更改为gnustl_shared。然后问题就消失了。但它不应该这样。
请注意,它仅适用于如下构建库
./build-android.sh --boost=1.55.0 --with-libraries=date_time,filesystem,program_options,regex,signals,system,thread,iostreams,random,log,serialization,graph $PATH_TO_NDK