我正在尝试使用 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;
}
安卓.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)
应用程序.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