質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

OpenSSL

OpenSSLはSSL/TLSのプロトコルと一般的な暗号のライブラリを導入するオープンソースのソフトウェアのツールキットです。

Q&A

解決済

1回答

4393閲覧

undefined reference to `SSL_library_init' in msys2

yumetodo

総合スコア5850

C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

OpenSSL

OpenSSLはSSL/TLSのプロトコルと一般的な暗号のライブラリを導入するオープンソースのソフトウェアのツールキットです。

0グッド

0クリップ

投稿2018/05/16 23:42

編集2018/05/16 23:46

msys2($MSYSTEM=MSYS)にて、wget 1.19.5のビルドをしようとして失敗しています。

ビルドには
https://github.com/Alexpux/MSYS2-packages/tree/master/wget
にあるPKGBUILDを

diff

1diff --git a/wget/PKGBUILD b/wget/PKGBUILD 2index 0a1009ed..7c142e2a 100644 3--- a/wget/PKGBUILD 4+++ b/wget/PKGBUILD 5@@ -1,7 +1,7 @@ 6 # Maintainer: Alexey Pavlov <alexpux@gmail.com> 7 8 pkgname=wget 9-pkgver=1.19.4 10+pkgver=1.19.5 11 pkgrel=1 12 pkgdesc="A network utility to retrieve files from the Web" 13 arch=('i686' 'x86_64') 14@@ -18,12 +18,13 @@ source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.lz{,.sig} 15 1.13.4-sysconfdir.patch 16 wget-1.14-msys2.patch 17 fix-gettext-version.patch) 18-sha256sums=('2fc0ffb965a8dc8f1e4a89cbe834c0ae7b9c22f559ebafc84c7874ad1866559a' 19+sha256sums=('29FBE6F3D5408430C572A63FE32BD43D5860F32691173DFD84EDC06869EDCA75' 20 'SKIP' 21 'c397093e82b50bcc6a4112a14b22d7426e67ce853d0dae65170aec6d7def4de8' 22 '162f4e63fe759e2eb7a507179d02f840143ee914b7f9a32bbb65afbfd6aa3640' 23- 'abedb6bae932fb3cda5d9c509fd0e7cd7fcf6f89c31feabc979ee624d5b130ef') 24-validpgpkeys=('7845120B07CBD8D6ECE5FF2B2A1743EDA91A35B6') # Tim Rühsen <tim.ruehsen@gmx.de> 25+ 'SKIP' #'abedb6bae932fb3cda5d9c509fd0e7cd7fcf6f89c31feabc979ee624d5b130ef' 26+ ) 27+validpgpkeys=('1CB27DBC98614B2D5841646D08302DB6A2670428') # Tim Rühsen <tim.ruehsen@gmx.de> 28 29 prepare() { 30 cd "${srcdir}/${pkgname}-${pkgver}"

のように書き換えビルドを試みたところ、

checking for libssl... no configure: error: --with-ssl=openssl was given, but SSL is not available.

と言われてしまいます。

該当箇所のconfigure.acを見ると

AS_IF([test x$ssl_found != xyes], [ dnl Now actually check for -lssl if it wasn't already found AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [ #include <openssl/ssl.h> #include <openssl/x509.h> #include <openssl/err.h> #include <openssl/rand.h> #include <openssl/des.h> #include <openssl/md4.h> #include <openssl/md5.h> ], [SSL_library_init ()]) if test x"$LIBSSL" != x then ssl_found=yes AC_MSG_NOTICE([compiling in support for SSL via OpenSSL]) AC_LIBOBJ([openssl]) LIBS="$LIBSSL $LIBS" AC_CHECK_FUNCS([RAND_egd]) elif test x"$with_ssl" != x then AC_MSG_ERROR([--with-ssl=openssl was given, but SSL is not available.]) fi ])

のようになっていたので、ここで新たに

c

1#include <openssl/ssl.h> 2#include <openssl/x509.h> 3#include <openssl/err.h> 4#include <openssl/rand.h> 5#include <openssl/des.h> 6#include <openssl/md4.h> 7#include <openssl/md5.h> 8int main(void) 9{ 10 SSL_library_init(); 11 return 0; 12}

というファイルを作成し、ビルドを試みると

$LC_ALL=C gcc `pkg-config --libs openssl` -std=c11 -v main.c Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/7.3.0/lto-wrapper.exe Target: x86_64-pc-msys Configured with: /msys_scripts/gcc/src/gcc-7.3.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libcilkrts --enable-libgomp --enable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible Thread model: posix gcc version 7.3.0 (GCC) COLLECT_GCC_OPTIONS='-std=c11' '-v' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-msys/7.3.0/cc1.exe -quiet -v -Dunix -idirafter /usr/lib/../lib/../include/w32api -idirafter /usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase main -std=c11 -version -o /tmp/ccv97hZn.s GNU C11 (GCC) version 7.3.0 (x86_64-pc-msys) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/include" ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-msys/7.3.0/include /usr/lib/gcc/x86_64-pc-msys/7.3.0/include-fixed /usr/include /usr/lib/../lib/../include/w32api End of search list. GNU C11 (GCC) version 7.3.0 (x86_64-pc-msys) compiled by GNU C version 7.3.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 50a02b1294cf36a12a47154a3c365050 COLLECT_GCC_OPTIONS='-std=c11' '-v' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/bin/as.exe -v -o /tmp/ccBaiDlz.o /tmp/ccv97hZn.s GNU assembler version 2.28 (x86_64-pc-msys) using BFD version (GNU Binutils) 2.28 COMPILER_PATH=/usr/lib/gcc/x86_64-pc-msys/7.3.0/:/usr/lib/gcc/x86_64-pc-msys/7.3.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/7.3.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/bin/ LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-msys/7.3.0/:/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/lib/:/usr/lib/:/usr/lib/w32api/ COLLECT_GCC_OPTIONS='-std=c11' '-v' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-msys/7.3.0/collect2.exe -plugin /usr/lib/gcc/x86_64-pc-msys/7.3.0/msys-lto_plugin.dll -plugin-opt=/usr/lib/gcc/x86_64-pc-msys/7.3.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/ccTn1EGo.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmsys-2.0 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=msys- --tsaware /usr/lib/../lib/crt0.o /usr/lib/gcc/x86_64-pc-msys/7.3.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-msys/7.3.0 -L/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/7.3.0/../../../../x86_64-pc-msys/lib -L/usr/lib/w32api -lssl -lz -lcrypto -lz /tmp/ccBaiDlz.o -lgcc_s --undefined=___deregister_frame_info --undefined=___register_frame_info -lgcc -lmsys-2.0 -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s --undefined=___deregister_frame_info --undefined=___register_frame_info -lgcc /usr/lib/../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-msys/7.3.0/crtend.o /tmp/ccBaiDlz.o:main.c:(.text+0xe): undefined reference to `SSL_library_init' /tmp/ccBaiDlz.o:main.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SSL_library_init' collect2: error: ld returned 1 exit status

undefined reference to `SSL_library_init'P

と言われます。-L/usr/lib/../lib-lsslは渡っており、

$pacman -Qs ssl local/liblzo2 2.10-1 (libraries compression) Portable lossless data compression library local/libopenssl 1.0.2.m-1 (libraries) The Open Source toolkit for Secure Sockets Layer and Transport Layer Security local/mingw-w64-i686-lz4 1.8.2-1 Very fast lossless compression algorithm (mingw-w64) local/mingw-w64-i686-lzo2 2.10-1 Portable lossless data compression library (mingw-w64) local/mingw-w64-i686-openssl 1.0.2.o-1 The Open Source toolkit for Secure Sockets Layer and Transport Layer Security (mingw-w64) local/mingw-w64-x86_64-lz4 1.8.2-1 Very fast lossless compression algorithm (mingw-w64) local/mingw-w64-x86_64-lzo2 2.10-1 Portable lossless data compression library (mingw-w64) local/mingw-w64-x86_64-openssl 1.0.2.o-1 The Open Source toolkit for Secure Sockets Layer and Transport Layer Security (mingw-w64) local/mingw-w64-x86_64-szip 2.1.1-1 Extended-Rice lossless compression algorithm implementation (mingw-w64) local/mingw-w64-x86_64-wavpack 5.1.0-1 Audio compression format with lossless, lossy and hybrid compression modes (mingw-w64) local/openssl 1.0.2.m-1 The Open Source toolkit for Secure Sockets Layer and Transport Layer Security local/openssl-devel 1.0.2.m-1 (development) Openssl headers and libraries local/perl-IO-Socket-SSL 2.054-1 (perl-modules) Nearly transparent SSL encapsulation for IO::Socket::INET local/perl-Net-SMTP-SSL 1.04-1 (perl-modules) SSL support for Net::SMTP local/perl-Net-SSLeay 1.84-1 (perl-modules) Perl extension for using OpenSSL local/ucl 1.03-2 Portable lossless data compression library written in ANSI C

のようにpacmanでopenssl-develが入っていて、

$ls /usr/lib | grep ssl libssl.a libssl.dll.a openssl/

のようにlibssl.aが存在し、

$objdump --syms /usr/lib/libssl.a | grep SSL_library_init [ 0](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 1) 0x0000000000000000 SSL_library_init

のようにシンボルが存在しているにもかかわらずです。

どうすればlinkに成功するでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

手元の環境では

gcc main.c `pkg-config --libs openssl`

としたところコンパイルできました。

gccのライブラリ読み込み順はむずかしい

投稿2018/05/17 03:16

asm

総合スコア15147

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yumetodo

2018/05/17 04:35

確かにそれだと通る・・・なんじゃそれ。 しかしそうするとconfigure.acはなんでコケているのだろう・・・
asm

2018/05/17 06:19

pkg-configでぐぐると、質問文のようにソースよりも前に付けるのが散見されるし gccのバージョンで-lオプションの扱いが変わったんじゃないだろうか 強引ですがconfigureの冒頭で ac_cv_libssl=yes 付けてconfigure実行 src/Makefileから -lunistring を2個所消してビルドできました。
asm

2018/05/17 08:18

CentOSにgcc7.3.0を入れて試したけどmain.cが後でも良さげですね・・・ mingw仕様か
yumetodo

2018/05/17 08:25

いや、Ubuntu 16.04LTS gcc5.5.0, gcc7.3.0でも再現するのでmingw関係ないですね
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問