c - 无法使用本地编译的 OpenSSL 加载 ibcrypto.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

这成功地解决了我的代码。但是当我试图通过以下命令破坏它时:

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 子模块加载的,就像这个问题中一样,以避免使用它可能过时的版本。

那么在第一种情况下,我如何判断加载动态库,甚至如何将OpenSSL构建为静态库呢?

您似乎没有将动态库的运行时搜索路径添加到可执行文件中。查看-rpath链接标志。最有可能的是,您需要在链接标志中添加类似-Wl,-rpath,${CURDIR}/builds/openssl/lib的内容。

最新更新