我有以下制作文件:
CC=g++
CFLAGS=-c -Wall
REST_LIBS = -lssl -lcrypto -lboost_system -lcpprest
all: main
main: static_pack
g++ -std=c++14 -D DEBUG -Wfatal-errors -static -pthread -I$(basepath)/vendors/cpp-jwt/include -I$(basepath)/vendors/json/include \
-DTS=\"/ctts.json\" \
-DCS_PATH=\"/bin\" \
-DCTFS_ENC=\"/ctfs.enc\" \
-DUNTAR_PATH=\"/\" \
-DCLUSTER_PATH=\"/.clusters\" \
-o run main.cpp \
libmain.a && \
rm -rf debpkg/cs/usr/bin/cs debpkg/cs.deb && \
cp run debpkg/cs/usr/bin/cs && \
dpkg-deb -b debpkg/cs && \
mv debpkg/cs.deb .
static_pack: rest.o aes.o random.o
ar rcs libmain.a random.o aes/aes.o rest/rest.o
rest.o:
g++ -std=c++14 -Wfatal-errors -c $(REST_LIBS) -o rest/rest.o rest/rest.cpp
aes.o: random.o
g++ -std=c++14 -D DEBUG -Wfatal-errors -c -lcrypto -o aes/aes.o random.o aes/aes.cpp
random.o:
g++ -std=c++14 -Wfatal-errors -c -o random.o random.cpp
如果我把它编译成动态链接,就不会有问题。但是,当我尝试静态编译时,会出现大量错误,例如:
aes.cpp:(.text+0x706): undefined reference to `EVP_DecryptInit_ex'
aes.cpp:(.text+0x732): undefined reference to `EVP_DecryptUpdate'
aes.cpp:(.text+0x763): undefined reference to `EVP_CIPHER_CTX_ctrl'
aes.cpp:(.text+0x792): undefined reference to `EVP_DecryptFinal_ex'
aes.cpp:(.text+0x7a1): undefined reference to `EVP_CIPHER_CTX_free'
基本上没有找到任何符号。我不知道我现在需要做什么。我尝试过将对象文件作为静态对象来构建,但失败了。我研究过链接顺序,但这似乎是对的。
我的问题归结为两件事:
-
当静态链接其他对象时,这些对象是否也需要静态编译+存档?
-
我的设置有什么问题?