【问题标题】:Failed to load ibcrypto.so.3 using the Locally compiled OpenSSL使用本地编译的 OpenSSL 加载 ibcrypto.so.3 失败
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • fwiw,另一个选项是export LD_LIBRARY_PATH=${CURDIR}builds/openssl/lib:$LD_LIBRARY_PATH
    • 不是一个真正的选择,因为每次你想运行二进制文件时,你都需要在你的环境中设置。
    • 严格来说,这仍然是一个选项 - 如果命令中存在拼写错误,则不需要重新构建 ;-) 还有另一个选项是将 openssl 构建为仅作为静态库。
    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多