- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下生成文件,我将以静态方式添加库“libcrypto.a”。我需要这样做,因为目标系统无法安装 openssl 库。
# Environment
MKDIR=mkdir
CP=cp
GREP=grep
NM=x86_64-linux-nm
CCADMIN=CCadmin
RANLIB=x86_64-linux-ranlib
CC=x86_64-linux-gnu-gcc
CCC=x86_64-linux-gnu-g++
CXX=x86_64-linux-gnu-g++
FC=x86_64-linux-gfortran
AS=x86_64-linux-as
# Macros
CND_PLATFORM=GNU-Linux
CND_DLIB_EXT=so
CND_CONF=Release_x86_64
CND_DISTDIR=dist
CND_BUILDDIR=build
# Include project Makefile
include Makefile
# Object Directory
OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
# Object Files
OBJECTFILES= \
${OBJECTDIR}/_ext/7daaf93a/DtaCommand.o \
${OBJECTDIR}/_ext/7daaf93a/DtaDev.o \
${OBJECTDIR}/_ext/7daaf93a/DtaDevGeneric.o \
${OBJECTDIR}/_ext/7daaf93a/DtaDevOpal.o \
${OBJECTDIR}/_ext/7daaf93a/DtaDevOpal1.o \
${OBJECTDIR}/_ext/7daaf93a/DtaDevOpal2.o \
${OBJECTDIR}/_ext/7daaf93a/DtaHashPwd.o \
${OBJECTDIR}/_ext/7daaf93a/DtaHexDump.o \
${OBJECTDIR}/_ext/7daaf93a/DtaResponse.o \
${OBJECTDIR}/_ext/7daaf93a/DtaSession.o \
${OBJECTDIR}/_ext/b7b9df0c/blockwise.o \
${OBJECTDIR}/_ext/b7b9df0c/chash.o \
${OBJECTDIR}/_ext/b7b9df0c/hmac.o \
${OBJECTDIR}/_ext/b7b9df0c/pbkdf2.o \
${OBJECTDIR}/_ext/b7b9df0c/sha1.o \
${OBJECTDIR}/_ext/822bcbe5/DtaDevLinuxNvme.o \
${OBJECTDIR}/_ext/822bcbe5/DtaDevLinuxSata.o \
${OBJECTDIR}/_ext/822bcbe5/DtaDevOS.o \
${OBJECTDIR}/GetPassPhrase.o \
${OBJECTDIR}/LinuxPBA.o \
${OBJECTDIR}/UnlockSEDs.o
# C Compiler Flags
CFLAGS=-m64
# CC Compiler Flags
CCFLAGS=-m64
CXXFLAGS=-m64
# Link Libraries and Options
LDLIBSOPTIONS=-lcurses -ltinfo
# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
"${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linuxpba
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linuxpba: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linuxpba ${OBJECTFILES} ${LDLIBSOPTIONS} -s
${OBJECTDIR}/_ext/7daaf93a/DtaCommand.o: ../Common/DtaCommand.cpp
${MKDIR} -p ${OBJECTDIR}/_ext/7daaf93a
${RM} "$@.d"
$(COMPILE.cc) -O2 -Werror -I../linux -I../Common -I../Common/pbkdf2 -std=c++11 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/_ext/7daaf93a/DtaCommand.o ../Common/DtaCommand.cpp
#...... SIMILAR FOR THE OTHER ELEMENTS OF "OBJECTDIR ......"
我试图在我的“LDLIBSOPTIONS”中添加一些东西,但我没有找到正确的方法,例如:
有什么建议吗?
最佳答案
OpenSSL link lincrypto.a in a static way
...
"-lcrypto" it links the library in a dynamic way (not good for my case)
使用 -l:libcrypto.a
。它指定库的全名。以下来自LD(1)
man page .请参阅有关 :filename
的部分。
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a .so extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.
The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.
See the
-(
option for a way to force the linker to search archives multiple times.You may list the same archive multiple times on the command line.
This type of archive searching is standard for Unix linkers. However, if you are using ld on AIX, note that it is different from the behaviour of the AIX linker.
"[absolute path]/libcrypto.a" it returns "libcrypto.a(dso_dlfcn.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line"
针对这个问题,在 libcrypto
和 libssl
中添加 -ldl
after你的链接命令。
"[absolute path]/libcrypto.a -ldl"libcrypto.a(evp_enc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
关于这个问题,参见What does .rodata and -fPIC mean when compiling OpenSSL?和 Compilation fails with “relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object” .
简而言之,您需要使用 shared
选项配置 OpenSSL。如果您不想构建共享库,请将 -fPIC
添加到 CFLAGS
。另见 Compilation and Installation在 OpenSSL wiki 上。
关于linux - OpenSSL 以静态方式链接 libcrypto.a,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45324091/
我是一名优秀的程序员,十分优秀!