gpt4 book ai didi

android - Boost Log V2 库 Android 链接

转载 作者:太空狗 更新时间:2023-10-29 15:06:18 26 4
gpt4 key购买 nike

我正在尝试使用 NDK 9C 在 Android 上构建 Boost 1.55 Log v2 库。我使用了补丁并使用 build-android.sh 构建了 boost,包括线程、iostreams、随机和日志选项。我使用了 Boost 的其他功能,它们都有效。但是 Log V2 似乎存在链接问题,我无法使用现有解决方案解决该问题。我不断收到相同的“ undefined reference ”错误。在网上,人们解决了这个问题,包括“#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

最佳答案

问题好像是静态库链接引起的问题是它寻找这样的符号:

boost::log::v2_mt_posix::core::set_filter

但是图书馆有符号:

boost::log::v2s_mt_posix::core::set_filter

如果#define BOOST_ALL_DYN_LINK 被删除并且 APP_STL 在 Application.mk 中从 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

关于android - Boost Log V2 库 Android 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com