安装仅项目的非系统版本的OpenSSL和libcrypt库 [英] Install a project-only non-system version of OpenSSL and libcrypt library

查看:338
本文介绍了安装仅项目的非系统版本的OpenSSL和libcrypt库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下Makefile的C项目:

I have a C project with the following Makefile:

CC=mpicc

buildsDir: ./builds
    mkdir ./builds

main: ./builds message dh main.c 
    $(CC) -o ./builds/main main.c ./builds/dh.o ./builds/message.o  -g -lcrypto -lssl

dh: ./builds dh.c dh.h
    $(CC) -c -o ./builds/dh.o dh.c -g -lcrypto -lssl

message: message.c message.h
    $(CC) -c -o ./builds/message.o -g ./message.c

run: main
    mpirun -quiet -np 3 xterm -hold -e ./builds/main &

debug: main
    mpirun -quiet -np 3 xterm -e gdb ./builds/main

.PHONY: clean

clean:
    rm -rf ./builds && mkdir ./builds

在我的系统中,我具有OpenSSL 1.0.2g:

And in my system I have the OpenSSL 1.0.2g:

OpenSSL 1.0.2g  1 Mar 2016
built on: reproducible build, date unspecified
platform: debian-amd64
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: cc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/lib/ssl"

但是在我的原型软件上,由于缺少系统提供的软件,因此我需要该软件的更高版本,并且我想避免在全球范围内安装它.因此,我认为使用的是仅限本地版本的pro项目的范围.我发现了这些说明,为我提供了一个很好的框架.

But on my prototype software I need a later version of it due to lack of the system-provided one and I want to avoid to install it globally. Thus I thought to use a local-only version limited pro project's scope. I found these instructions that offer me a great framework.

我还要做的第一步是将其作为我项目的子模块:

Also I did the first step to add is as a submodule to my project:

[submodule "openssl"]
    path = openssl
    url = https://github.com/openssl/openssl.git
    branch = OPENSSL_1_1_1a

在控制台上,我尝试使用以下命令集手动构建它:

On console I tried to build it manually using the following command set:

cd openssl
./config --prefix=$(pwd)/../builds/openssl --openssldir=$(pwd)/../builds/openssl
make && make test && make install

现在我想走得更远,以某种方式打电话给mpicc,以链接以某种方式位于builds目录中的build openssl lib,但是我不知道.

And now I want to go further and somehow to tel the mpicc to link the build openssl lib located somehow the builds dir but I do not know that.

推荐答案

如何更改这样的makefile?

How about changing your makefile like this?

CC=mpicc

# use headers from builds/openssl
CFLAGS := -g -Ibuilds/openssl/include

# look for library in builds/openssl
LDFLAGS := -Lbuilds/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
       .... your openssl build command ....

请检查builds/openssl的布局以获取正确的包含&库路径.

Please check the layout of builds/openssl for the correct include & library paths.

奖金代码我个人将重新构建makefile.为什么不让繁重的工作呢?

BONUS CODE personally I would restructure the makefile. Why not let make handle the heavy lifting?

LDFLAGS := -g -Lbuilds/openssl/lib

SRCS := main.c dh.c message.c
OBJS := $(SRCS:%.c=builds/%.o)
...
builds/main: $(OBJS)
    $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

# do not re-build when "builds" directory contents change
$(OBJS): | builds
$(OBJS): builds/%.o: %.c
    $(CC) $(CFLAGS) -o $@ -c $<

# if you want to build openssl with your makefile...
$(OBJS): builds/openssl

这篇关于安装仅项目的非系统版本的OpenSSL和libcrypt库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆