c++ - Autotools 和 OpenSSL MD5/RAND_bytes 未定义

标签 c++ gcc autotools

出于某种原因,我在这个特定的 C++ 文件中得到了 MD5 和 RAND_bytes 的 undefined symbol 。 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=共享库

生成两组共享对象位于:

/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

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

最佳答案

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

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

关于c++ - Autotools 和 OpenSSL MD5/RAND_bytes 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24190462/

相关文章:

c++ - 从 Visual Studio 2012 编译到 g++?

c - 使用 autotools 链接 gstreamer 插件中的外部库

c++ - 如何使用键而不是标量检索 map 节点?

delphi - 无法解析的链接错误 E2065 与 XXH32(xxHash 和 lz4)

python - 在没有内存泄漏的情况下在 Python 中公开 STL 结构

c - GCC 将所有字符串存储在 .rodata 中

c++ - 在 Windows 中运行 autotools (MinGW)

linux - 扩展应用核心

c++ - 将 RTP vp8 有效负载数据包保存到 .webm 文件

c++ - 使用 unordered_map 移动构造函数