使用本地编译的OpenSSL未能加载ibcrypto.so.3

时间:2019-02-06 15:52:53

标签: c openssl mpi linker-errors dynamic-linking

我有以下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)?

1 个答案:

答案 0 :(得分:0)

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