我想编译自己的动态链接库(.so),我们假设它的名称为worker_lib.so
。
worker_lib.so
依赖于其他动态链接库,例如libprotobuf-lite.so
,libprotobuf.so
和libprotoc.so
。这些库位于目录(deps / lib)中。
如何编译我自己的动态链接库(worker_lib.so
),包括依赖于它们的库(libprotobuf-lite.so
,libprotobuf.so
...)
注意,我想用cmd或Makefile
完成它。
总而言之,我想将ps-lite(https://github.com/dmlc/ps-lite)编译为.so。
相关帖子为Linking a shared library with another shared lib in linux。 但是答案不能解决我的问题。
(info "ps start")
ifdef config
$(info "isconfig")
include $(config)
endif
include make/ps.mk
ifndef CXX
CXX = g++
endif
ifndef DEPS_PATH
DEPS_PATH = $(shell pwd)/deps
endif
ifndef PROTOC
PROTOC = ${DEPS_PATH}/bin/protoc
endif
INCPATH = -I./pssrc -I./include -I$(DEPS_PATH)/include
CFLAGS = -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions $(INCPATH) $(ADD_CFLAGS)
include make/deps.mk
lint:
python tests/lint.py ps all include/ps pssrc
ps: build/libps.a
pslib: build/lib/worker_lib.so
PS_OBJS = $(addprefix build/, customer.o postoffice.o van.o meta.pb.o)
PS_LIB_SRC = $(addprefix build/, customer.o postoffice.o van.o meta.pb.o worker.o)
build/lib/worker_lib.so: $(PS_LIB_SRC)
@mkdir -p build/lib
$(CXX) -shared -Xlinker --unresolved-symbols=ignore-in-shared-libs $^ -o $@ $(CFLAGS)
build/libps.a: $(PS_OBJS)
ar crv $@ $(filter %.o, $?)
build/%.o: pssrc/%.cc ${ZMQ} pssrc/meta.pb.h
@mkdir -p $(@D)
$(CXX) $(INCPATH) -std=c++0x -MM -MT build/$*.o $< >build/$*.d
$(CXX) $(CFLAGS) -c $< -o $@
pssrc/%.pb.cc pssrc/%.pb.h : pssrc/%.proto ${PROTOBUF}
$(PROTOC) --cpp_out=./pssrc --proto_path=./pssrc $<
-include build/*.d
-include build/*/*.d
我想make pslib
编译worker_lib.so
。但是当我make pslib
时,我遇到以下问题:
error information
错误信息如下:
/home/xiaonan/hbsun/hbsun_Athena/deps/bin/protoc --cpp_out=./pssrc --proto_path=./pssrc pssrc/meta.proto
g++ -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -std=c++0x -MM -MT build/customer.o pssrc/customer.cc >build/customer.d
g++ -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -c pssrc/customer.cc -o build/customer.o
g++ -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -std=c++0x -MM -MT build/postoffice.o pssrc/postoffice.cc >build/postoffice.d
g++ -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -c pssrc/postoffice.cc -o build/postoffice.o
g++ -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -std=c++0x -MM -MT build/van.o pssrc/van.cc >build/van.d
g++ -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -c pssrc/van.cc -o build/van.o
g++ -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -std=c++0x -MM -MT build/meta.pb.o pssrc/meta.pb.cc >build/meta.pb.d
g++ -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -c pssrc/meta.pb.cc -o build/meta.pb.o
g++ -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -std=c++0x -MM -MT build/worker.o pssrc/worker.cc >build/worker.d
g++ -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include -c pssrc/worker.cc -o build/worker.o
g++ -shared -Xlinker --unresolved-symbols=ignore-in-shared-libs build/customer.o build/postoffice.o build/van.o build/meta.pb.o build/worker.o -o build/lib/worker_lib.so -std=c++11 -msse2 -fPIC -O3 -ggdb -Wall -lpthread -finline-functions -I./pssrc -I./include -I/home/xiaonan/hbsun/hbsun_Athena/deps/include
build/van.o: In function `ps::Van::UnpackMeta(char const*, int, ps::Meta*)':
/root/hbsun/hbsun_Athena/pssrc/van.cc:464: undefined reference to `google::protobuf::MessageLite::ParseFromArray(void const*, int)'
build/van.o: In function `google::protobuf::RepeatedField<int>::Get(int) const':
/home/xiaonan/hbsun/hbsun_Athena/deps/include/google/protobuf/repeated_field.h:1182: undefined reference to `google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)'
/home/xiaonan/hbsun/hbsun_Athena/deps/include/google/protobuf/repeated_field.h:1182: undefined reference to `google::protobuf::internal::LogMessage::operator<<(char const*)'
/home/xiaonan/hbsun/hbsun_Athena/deps/include/google/protobuf/repeated_field.h:1182: undefined reference to `google::protobuf::internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)'
/home/xiaonan/hbsun/hbsun_Athena/deps/include/google/protobuf/repeated_field.h:1182: undefined reference to `google::protobuf::internal::LogMessage::~LogMessage()'