【发布时间】:2019-06-30 15:21:57
【问题描述】:
我有以下Makefile:
CC=mpicc
# use headers from builds/openssl
CFLAGS := -g -I${CURDIR}builds/openssl/include/openssl
# look for library in builds/openssl
LDFLAGS := -L${CURDIR}builds/openssl/lib
LIBS := -lcrypto -lssl
.PHONY: all
all: builds/main
builds:
mkdir -p $@
builds/main: builds/dh.o builds/message.o
builds/main: main.c
$(CC) $(CFLAGS) -o $@ $< builds/dh.o builds/message.o $(LDFLAGS) $(LIBS)
builds/dh.o: dh.h
builds/dh.o: dh.c
$(CC) $(CFLAGS) -o $@ -c $<
builds/message.o: message.h
builds/message.o: message.c
$(CC) $(CFLAGS) -o $@ -c $<
builds/dh.o builds/message.o builds/main: builds
# if you want to build openssl with your makefile...
builds/dh.o builds/message.o builds/main: builds/openssl
builds/openssl: builds
cd openssl && ./config --prefix=${CURDIR}/builds/openssl --openssldir=${CURDIR}/builds/openssl && make && make test && make install
.PHONY: run
run: builds/main
mpirun -quiet -np 3 xterm -hold -e ./builds/main &
.PHONY: debug
debug: builds/main
mpirun -quiet -np 3 xterm -e gdb ./builds/main
.PHONY: clean
clean:
rm -rf ./builds
这成功地完成了我的代码。但是当我尝试通过这些命令破坏它时:
make clean && make run
应用程序运行但我收到以下错误:
./builds/main: 加载共享库时出错:libcrypto.so.3: 无法打开共享对象文件”没有这样的文件或目录
我试图像这样更改我的Makefile:
CC=mpicc
# use headers from builds/openssl
CFLAGS := -g -I${CURDIR}builds/openssl/include/openssl
# look for library in builds/openssl
LDFLAGS := -L${CURDIR}builds/openssl/lib
LIBS := -lcrypto -lssl
.PHONY: all
all: builds/main
builds:
mkdir -p $@
builds/main: builds/dh.o builds/message.o
builds/main: main.c
$(CC) $(CFLAGS) -o $@ $< builds/dh.o builds/message.o $(LDFLAGS) $(LIBS)
builds/dh.o: dh.h
builds/dh.o: dh.c
$(CC) $(CFLAGS) -o $@ -c $<
builds/message.o: message.h
builds/message.o: message.c
$(CC) $(CFLAGS) -o $@ -c $<
builds/dh.o builds/message.o builds/main: builds
# if you want to build openssl with your makefile...
builds/dh.o builds/message.o builds/main: builds/openssl
builds/openssl: builds
cd openssl && ./config --prefix=${CURDIR}/builds/openssl --openssldir=${CURDIR}/builds/openssl && make && make test && make install
.PHONY: run
run: builds/main
mpirun -quiet -np 3 xterm -hold -e ./builds/main &
.PHONY: debug
debug: builds/main
mpirun -quiet -np 3 xterm -e gdb ./builds/main
.PHONY: clean
clean:
rm -rf ./builds
而且完全编译失败:
main.c: In function ‘main’:
main.c:76:10: warning: implicit declaration of function ‘DH_get0_pub_key’ [-Wimplicit-function-declaration]
pubKey=DH_get0_pub_key(secret);
^
main.c:76:9: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
pubKey=DH_get0_pub_key(secret);
^
main.c:125:5: warning: implicit declaration of function ‘DH_get0_p’ [-Wimplicit-function-declaration]
p=DH_get0_p(secret);
^
main.c:125:4: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
p=DH_get0_p(secret);
^
/tmp/ccgccndI.o: In function `main':
/home/pcmagas/Kwdikas/master_thesis/mpi_dh/main.c:76: undefined reference to `DH_get0_pub_key'
/home/pcmagas/Kwdikas/master_thesis/mpi_dh/main.c:125: undefined reference to `DH_get0_p'
builds/dh.o: In function `generateKeys':
/home/pcmagas/Kwdikas/master_thesis/mpi_dh/dh.c:20: undefined reference to `DH_set0_pqg'
builds/dh.o: In function `generateKeyFromPreviousParticipant':
/home/pcmagas/Kwdikas/master_thesis/mpi_dh/dh.c:136: undefined reference to `DH_get0_priv_key'
/home/pcmagas/Kwdikas/master_thesis/mpi_dh/dh.c:147: undefined reference to `DH_get0_p'
collect2: error: ld returned 1 exit status
Makefile:18: recipe for target 'builds/main' failed
如果与原始结果相比,意思是根本看不到库,而在第一个错误时,我的项目已成功编译但无法加载动态库。
OpenSSL 是通过 git 子模块加载的,就像在这个 question 中一样,以避免使用可能过时的版本。
那么我如何知道在第一种情况下加载动态库,甚至如何将 OpenSSL 构建为静态库/(ries)?
【问题讨论】:
标签: c openssl mpi linker-errors dynamic-linking