我使用boost c ++库实现了一个迷你共享库。我在我的平台编译了最后一个boost版本。我在系统中安装了库。然后我试着编译项目。一切正常,但是当我尝试加载库或使用ldd检查.so lib时,有未定义的变量。
这是编译输出:
jni:
[echo] Generating JNI headers
[exec] mkdir -p target/c++
[exec] g++ -c -Wall -fPIC -I/usr/lib/jvm/java-8-oracle/include/ -I/usr/lib/jvm/java-8-oracle/include/linux -I/usr/include/boost_1_66_0 -o target/c++/ext_concurrent_fiber_NativeFiber.o src/main/c++/ext_concurrent_fiber_NativeFiber.cpp
[exec] mkdir -p target/c++
[exec] g++ -c -Wall -fPIC -I/usr/lib/jvm/java-8-oracle/include/ -I/usr/lib/jvm/java-8-oracle/include/linux -I/usr/include/boost_1_66_0 -o target/c++/ext_concurrent_fiber_RecursiveMutex.o src/main/c++/ext_concurrent_fiber_RecursiveMutex.cpp
[exec] mkdir -p target/c++
[exec] g++ -c -Wall -fPIC -I/usr/lib/jvm/java-8-oracle/include/ -I/usr/lib/jvm/java-8-oracle/include/linux -I/usr/include/boost_1_66_0 -o target/c++/ext_concurrent_fiber_RWRecursiveMutex.o src/main/c++/ext_concurrent_fiber_RWRecursiveMutex.cpp
[exec] g++ -Wall -g -O -fPIC -shared -L /usr/include/boost_1_66_0/stage/lib -lboost_fiber -o target/classes/libnativefibers.so target/c++/ext_concurrent_fiber_NativeFiber.o target/c++/ext_concurrent_fiber_RecursiveMutex.o target/c++/ext_concurrent_fiber_RWRecursiveMutex.o
这是makefile
CC=g++
CFLAGS=-c -Wall -fPIC -I/usr/lib/jvm/java-8-oracle/include/ -I/usr/lib/jvm/java-8-oracle/include/linux -I/usr/include/boost_1_66_0
CPPFLAGS=-Wall -g -O -fPIC
LDFLAGS=-shared -L /usr/include/boost_1_66_0/stage/lib -lboost_fiber
SOURCES_DIR=src/main/c++
OBJECTS_DIR=target/c++
EXECUTABLE=target/classes/libnativefibers.so
SOURCES=$(shell find '$(SOURCES_DIR)' -type f -name '*.cpp')
OBJECTS=$(SOURCES:$(SOURCES_DIR)/%.cpp=$(OBJECTS_DIR)/%.o)
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(CPPFLAGS) $(LDFLAGS) -o $(EXECUTABLE) $^
$(OBJECTS):
mkdir -p $(OBJECTS_DIR)
$(CC) $(CFLAGS) -o $@ $(SOURCES_DIR)/$(basename $(notdir $@)).cpp
clean:
rm -rf $(OBJECTS_DIR) $(EXECUTABLE)
这是ld target / classes / libnativefibers.so
的输出ld: attenzione: impossibile trovare il simbolo d'ingresso _start; l'indirizzo iniziale non viene impostato
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::scheduler::set_algo(boost::intrusive_ptr<boost::fibers::algo::algorithm>)"
target/classes/libnativefibers.so: riferimento non definito a "vtable for boost::fibers::context"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::fiber::detach()"
target/classes/libnativefibers.so: riferimento non definito a "typeinfo for boost::fibers::context"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::recursive_mutex::lock()"
target/classes/libnativefibers.so: riferimento non definito a "ontop_fcontext"
target/classes/libnativefibers.so: riferimento non definito a "jump_fcontext"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::context::~context()"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::fiber::start_()"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::recursive_mutex::unlock()"
target/classes/libnativefibers.so: riferimento non definito a "make_fcontext"
target/classes/libnativefibers.so: riferimento non definito a "vtable for boost::fibers::algo::shared_work"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::fiber::join()"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::context::active()"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::context::terminate()"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::context::get_id() const"
target/classes/libnativefibers.so: riferimento non definito a "boost::context::stack_traits::default_size()"
target/classes/libnativefibers.so: riferimento non definito a "boost::fibers::recursive_mutex::try_lock()"
使用Test类的结果是:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/libnativefibers4038906104222457167.so: /tmp/libnativefibers4038906104222457167.so: undefined symbol: _ZTIN5boost6fibers7contextE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at ext.concurrent.fiber.NativeFiber.loadLibrary(NativeFiber.java:42)
at ext.concurrent.fiber.NativeFiber.<clinit>(NativeFiber.java:11)
at ext.concurrent.Test.main(Test.java:8)