>我有以下制作文件:
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'
基本上没有找到任何符号。我不确定我现在需要做什么。我尝试将目标文件构建为静态文件,但失败了。我已经研究了链接顺序,但这似乎是正确的。
我的问题归结为两件事:
静态链接其他对象时,这些对象是否需要静态编译+存档?
我的设置有什么问题?
rest.o
规则不需要REST_LIBS
,因为它只编译源文件。你需要在规则中将这些库传递给 g++main
- 作为其中的一部分,g++ 将调用链接器。
好的,所以显然链接的顺序与我想象的相反......而且我认为我可能最初没有将这两个链接为fufu错误。
REST_LIBS = -lboost_filesystem -lboost_system -lcpprest -lssl -lcrypto -ldl
# /usr/local/lib/libyaml-cpp.a
all: main
main: static_pack
g++ -std=c++14 -D DEBUG -Wfatal-errors -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 $(REST_LIBS) -pthread &&
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 .