【问题标题】:Autotools and OpenSSL MD5/RAND_bytes undefinedAutotools 和 OpenSSL MD5/RAND_bytes 未定义
【发布时间】:2014-06-12 17:27:59
【问题描述】:

由于某种原因,我在这个特定的 C++ 文件中得到了 MD5 和 RAND_bytes 的未定义符号。 OpenSSL 已将自身(libssl 和 libcrypto)安装到 /usr/lib 和 /usr/include/openssl/。

libtool: link: (cd ".libs" && rm -f "libeapgpsk.so.1" && ln -s "libeapgpsk.so.1.0.0" "libeapgpsk.so.1")
libtool: link: (cd ".libs" && rm -f "libeapgpsk.so" && ln -s "libeapgpsk.so.1.0.0" "libeapgpsk.so")
libtool: link: ar cru .libs/libeapgpsk.a  eap-gpsk/eap_gpsk_fsm.o
libtool: link: ranlib .libs/libeapgpsk.a
libtool: link: ( cd ".libs" && rm -f "libeapgpsk.la" && ln -s "../libeapgpsk.la" "libeapgpsk.la" )
depbase=`echo tests/md5_test.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
    g++ -DPACKAGE_NAME=\"OpenDiameter\" -DPACKAGE_TARNAME=\"opendiameter\" -DPACKAGE_VERSION=\"1.0.7-i\" -DPACKAGE_STRING=\"OpenDiameter\ 1.0.7-i\" -DPACKAGE_BUGREPORT=\"vfajardo@tari.toshiba.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"opendiameter\" -DVERSION=\"1.0.7-i\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_IFADDRS_H=1 -DHAVE_SHADOW_H=1 -DHAVE__BOOL=1 -DHAVE_STDBOOL_H=1 -DHAVE_GETIFADDRS=1 -I.  -Wall -I/usr -I/usr -fno-strict-aliasing -I../include -I../libeap/include -DOS_LINUX -I/usr/include/openssl  -I/usr/include/openssl -MT tests/md5_test.o -MD -MP -MF $depbase.Tpo -c -o tests/md5_test.o tests/md5_test.cxx &&\
    mv -f $depbase.Tpo $depbase.Po
In file included from ../include/aaa_dictionary_api.h:45:0,
                 from ../include/aaa_parser_api.h:38,
                 from ../libeap/include/eap.hxx:54,
                 from tests/md5_test.cxx:45:
../include/framework.h:1653:7: warning: ‘typedef’ was ignored in this declaration [enabled by default]
In file included from ../include/aaa_parser_api.h:38:0,
                 from ../libeap/include/eap.hxx:54,
                 from tests/md5_test.cxx:45:
../include/aaa_dictionary_api.h:58:1: warning: ‘typedef’ was ignored in this declaration [enabled by default]
tests/md5_test.cxx: In constructor ‘EapTask::EapTask()’:
tests/md5_test.cxx:71:45: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘PeerApplication::PeerApplication(EapTask&, ACE_Semaphore&)’:
tests/md5_test.cxx:418:72: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘StandAloneAuthApplication::StandAloneAuthApplication(EapTask&, ACE_Semaphore&)’:
tests/md5_test.cxx:460:80: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘BackendAuthApplication::BackendAuthApplication(EapTask&, ACE_Semaphore&, bool)’:
tests/md5_test.cxx:514:58: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
tests/md5_test.cxx: In constructor ‘PassThroughAuthApplication::PassThroughAuthApplication(EapTask&, ACE_Semaphore&, bool)’:
tests/md5_test.cxx:576:62: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
/bin/bash ../libtool --tag=CXX   --mode=link g++  -I/usr/include/openssl -L/usr/lib  -o md5_test tests/md5_test.o -ldl -lssl -lcrypto -lACE_SSL -lACE -lACEXML_Parser -lACEXML -lpthread -lboost_system -lboost_thread -lboost_system -lboost_thread -lACEXML -lACEXML_Parser -ldl -lssl -lcrypto ../libeap/libeap.la ../libeap/libeaparchie.la ../libeap/libeapgpsk.la -lboost_system -lboost_thread -lACEXML -lACEXML_Parser -ldl -lssl -lcrypto
libtool: link: g++ -I/usr/include/openssl -o .libs/md5_test tests/md5_test.o  -L/usr/lib /usr/lib/libACE_SSL.so /usr/lib/libACE.so -lpthread ../libeap/.libs/libeap.so ../libeap/.libs/libeaparchie.so ../libeap/.libs/libeapgpsk.so -lboost_system -lboost_thread /usr/lib/libACEXML.so /usr/lib/libACEXML_Parser.so -ldl -lssl -lcrypto
../libeap/.libs/libeap.so: undefined reference to `MD5@OPENSSL_1.0.0'
../libeap/.libs/libeap.so: undefined reference to `RAND_bytes@OPENSSL_1.0.0'
collect2: ld returned 1 exit status

这是负责这个的 Makefile.am:

## Process this file with automake to produce Makefile.in

srcdir = @srcdir@
VPATH = @srcdir@

AM_CPPFLAGS = @L_CPPFLAGS@ \
              -I@top_srcdir@/include \
              -I@top_srcdir@/libeap/include \
              -D@HOST_OS@
AM_LDFLAGS = @L_LDFLAGS@

if compile_EAPTLS
CORE_SRC = eapcore/eap_fsm.cxx \
    eapcore/eap_peerfsm.cxx \
    eapcore/eap_authfsm.cxx \
        eapcore/eap_standalone_authfsm.cxx \
        eapcore/eap_backend_authfsm.cxx \
        eapcore/eap_passthrough_authfsm.cxx \
    eapcore/eap_identity.cxx \
    eapcore/eap_method_registrar.cxx \
    eapcore/eap_policy.cxx \
        eapcore/eap_notification.cxx \
    eapcore/eap_md5.cxx 

CORE_HDR = include/eap_api.h \
        include/eap.hxx \
        include/eap_authfsm.hxx \
        include/eap_fsm.hxx \
        include/eap_identity.hxx \
        include/eap_log.hxx \
        include/eap_md5.hxx \
        include/eap_method_registrar.hxx \
        include/eap_notification.hxx \
        include/eap_parser.hxx \
        include/eap_peerfsm.hxx \
        include/eap_policy.hxx \
    include/eap_archie_crypto.hxx \
    include/eap_archie_fsm.hxx \
    include/eap_archie_parser.hxx \
    include/eap_archie.hxx \
    include/eap_gpsk_crypto.hxx \
    include/eap_gpsk_fsm.hxx \
    include/eap_gpsk_parser.hxx \
    include/eap_gpsk.hxx \
    include/eap_tls.hxx \
    include/eap_tls_mng.hxx \
    include/eap_tls_session.hxx \
    include/eap_tls_parser.hxx \
    include/eap_tls_fsm.hxx \
    include/eap_tls_xml_data.hxx \
    include/eap_tls_xml_parser.hxx \
    include/eap_tls_data_defs.hxx
else
CORE_SRC = eapcore/eap_fsm.cxx \
    eapcore/eap_peerfsm.cxx \
    eapcore/eap_authfsm.cxx \
        eapcore/eap_standalone_authfsm.cxx \
        eapcore/eap_backend_authfsm.cxx \
        eapcore/eap_passthrough_authfsm.cxx \
    eapcore/eap_identity.cxx \
    eapcore/eap_method_registrar.cxx \
    eapcore/eap_policy.cxx \
        eapcore/eap_notification.cxx \
    eapcore/eap_md5.cxx

CORE_HDR = include/eap_api.h \
        include/eap.hxx \
        include/eap_authfsm.hxx \
        include/eap_fsm.hxx \
        include/eap_identity.hxx \
        include/eap_log.hxx \
        include/eap_md5.hxx \
        include/eap_method_registrar.hxx \
        include/eap_notification.hxx \
        include/eap_parser.hxx \
        include/eap_peerfsm.hxx \
        include/eap_policy.hxx \
    include/eap_archie_crypto.hxx \
    include/eap_archie_fsm.hxx \
    include/eap_archie_parser.hxx \
    include/eap_archie.hxx \
    include/eap_gpsk_crypto.hxx \
    include/eap_gpsk_fsm.hxx \
    include/eap_gpsk_parser.hxx \
    include/eap_gpsk.hxx
endif

ARCHIE_SRC = eap-archie/eap_archie_fsm.cxx

GPSK_SRC = eap-gpsk/eap_gpsk_fsm.cxx

if compile_EAPTLS
TLS_SRC = eap-tls/eap_tls_mng.cxx \
          eap-tls/eap_tls_crypto.cxx \
          eap-tls/eap_tls_fsm.cxx \
          eap-tls/eap_tls_xml_data.cxx \
          eap-tls/eap_tls_xml_parser.cxx
endif

includedir = $(prefix)/include/opendiameter/eap
include_HEADERS = $(CORE_HDR)

sysconfdir = $(prefix)/etc/opendiameter/eap
sysconf_DATA = config/client.eap-tls.xml \
               config/server.eap-tls.xml

if compile_EAPTLS
lib_LTLIBRARIES = libeap.la libeaparchie.la libeapgpsk.la libeaptls.la
else
lib_LTLIBRARIES = libeap.la libeaparchie.la libeapgpsk.la
endif

libeap_la_SOURCES = $(CORE_SRC) $(CORE_HDR)
libeaparchie_la_SOURCES = $(ARCHIE_SRC)
libeapgpsk_la_SOURCES = $(GPSK_SRC)

if compile_EAPTLS
libeaptls_la_SOURCES = $(TLS_SRC)
endif

libeap_la_LIBADD = -ldl -lssl -lcrypto
libeap_la_LDFLAGS = -version-info 1:0:0 -lssl -lcrypto
libeap_la_AR = $(AR) -qcs

libeaparchie_la_LDFLAGS = -version-info 1:0:0 
libeaparchie_la_AR = $(AR) -qcs

libeapgpsk_la_LDFLAGS = -version-info 1:0:0 
libeapgpsk_la_AR = $(AR) -qcs

if compile_EAPTLS
libeaptls_la_LDFLAGS = -version-info 1:0:0 
libeaptls_la_AR = $(AR) -qcs
LDADD = @L_LIBS@ \
        $(top_builddir)/libeap/libeap.la \
        $(top_builddir)/libeap/libeaparchie.la \
        $(top_builddir)/libeap/libeapgpsk.la \
        $(top_builddir)/libeap/libeaptls.la \
        $(top_builddir)/libdiamparser/libdiamparser.la
else
LDADD = @L_LIBS@ \
        $(top_builddir)/libeap/libeap.la \
        $(top_builddir)/libeap/libeaparchie.la \
        $(top_builddir)/libeap/libeapgpsk.la
endif

if compile_EAPTLS
noinst_PROGRAMS = md5_test archie_test gpsk_test tls_test
else
noinst_PROGRAMS = md5_test archie_test gpsk_test
endif

md5_test_SOURCES = tests/md5_test.cxx -lssl -lcrypto

archie_test_SOURCES = tests/archie_test.cxx 

gpsk_test_SOURCES = tests/gpsk_test.cxx 

if compile_EAPTLS
tls_test_SOURCES = tests/tls_test.cxx
endif

EXTRA_DIST = config

我怀疑 autotools 没有做某事,因为我没有指定它这样做。在文件md5_test.c里面,但是还是报错。

#include <openssl/md5.h>
#include <openssl/rand.h>

任何帮助将不胜感激。

编辑: 我深入研究了库以查看是否有版本信息,这让我陷入了这个非常有趣的困境 - 使用以下命令编译时 openssl 1.0.0m:./config --prefix=/usr --openssldir=/etc/ssl - -libdir=lib 共享

生成两组共享对象,位于:

/usr/lib/x86_64-linux-gnu/
/usr/lib

/usr/lib/x86_64-linux-gnu/中的共享对象产生一个版本(使用objdump -T)

00000000001546b0 g    DF .text  0000000000000108  OPENSSL_1.0.0 PKCS7_to_TS_TST_INFO

/usr/lib 中的共享对象产生这个:

000000000012ee20 g    DF .text  000000000000000c  Base        BIO_new_CMS

如何解决这个问题,因为这看起来非常不标准......?

【问题讨论】:

  • 您的-lssl 是否找到了不包含版本 1.0.0 符号的旧版本 libssl(例如 MD5@OPENSSL_1.0.0)?
  • 我已经编译并安装了 openssl 1.0.0m,所以我会这样想:rbrash@megatron:~/Downloads/diameter-svn/cplusplus$ sudo nm -D /usr/lib/libcrypto.so | grep md5 00000000000db570 T EVP_md5 0000000000067c30 T md5_block_asm_data_order rbrash@megatron:~/Downloads/diameter-svn/cplusplus$ sudo nm -D /usr/lib/libcrypto.so | grep MD5 0000000000067bb0 T MD5 00000000000679d0 T MD5_Final 0000000000067b00 T MD5_Init 00000000000679c0 T MD5_Transform 00000000000677a0 T MD5_Update

标签: c++ gcc autotools


【解决方案1】:

从您的库的LDFLAGS 中删除-lssl -lcrypto;链接编辑器的工作方式,LDFLAGS 在目标文件之前传递,这意味着它们被丢弃;至少在某些版本的链接编辑器中,在目标文件之前传递的库也被“列入黑名单”,或者准确地说,它们在再次传递时会被忽略。

您在LDFLAGSLIBADD 中都传递了两次-lssl -lcrypto,因此您可能会触发该行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多