使用独立工具链为android构建squid时未定义的引用错误

时间:2017-02-26 12:34:01

标签: gcc makefile android-ndk cross-compiling toolchain

我正在尝试为android构建squid-3.5.24。我正在使用android-ndk-r10e进行构建。 这是我的环境。基于此:https://gist.github.com/nddrylliog/4688209

#!/bin/sh

# I put all my dev stuff in here
export DEV_PREFIX=$HOME/Documents

# Don't forget to adjust this to your NDK path
export ANDROID_NDK=$HOME/Android/android-ndk-r10e

export CROSS_COMPILE=arm-linux-androideabi

# I chose the gcc-4.7 toolchain - works fine for me!
export ANDROID_PREFIX=$DEV_PREFIX/toolchain/arm-linux-androideabi-4.8

# Apparently android-8 works fine, there are other versions, look them up
export SYSROOT=${ANDROID_PREFIX}/sysroot

export CROSS_PATH=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}

# Non-exhaustive lists of compiler + binutils
# Depending on what you compile, you might need more binutils than that
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

export PATH=$PATH:$ANDROID_PREFIX/bin
export PATH=$PATH:${SYSROOT}/usr/lib
# This is just an empty directory where I want the built objects to be installed
export PREFIX=${SYSROOT}

# Don't mix up .pc files from your host and build target
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig

# You can clone the full Android sources to get bionic if you want.. I didn't
# want to so I just got linker.h from here: http://gitorious.org/0xdroid/bionic
# Note that this was only required to build boehm-gc with dynamic linking support.
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"

./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} --cache-file=squid.cache "$@"

configure成功完成后我运行了make。在编译期间,我收到此错误:

/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:535: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:535: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/locale_facets.h:869: error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/locale_facets.h:869: error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
collect2: error: ld returned 1 exit status
make[3]: *** [basic_smb_lm_auth] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive] Error 1

我认为该错误与链接器无法找到libstdc++libstdc++--v3有关,但这些库存在sysroot/usr/lib中,已经提供给ld

我尝试将这些库直接与-lstdc++--v3-lstdc++相关联,但这似乎与配置中的gcc混乱。

目前在我的智慧结束时,有人能指出我正确的方向吗?

以下是make的其余输出:

Making all in compat
make[1]: Nothing to be done for `all'.
Making all in lib
Making all in snmplib
make[2]: Nothing to be done for `all'.
Making all in rfcnb
make[2]: Nothing to be done for `all'.
Making all in smblib
make[2]: Nothing to be done for `all'.
Making all in ntlmauth
make[2]: Nothing to be done for `all'.
make[2]: Nothing to be done for `all-am'.
Making all in libltdl
/Library/Developer/CommandLineTools/usr/bin/make  all-am
make[2]: Nothing to be done for `all-am'.
Making all in scripts
make[1]: Nothing to be done for `all'.
Making all in icons
make[1]: Nothing to be done for `all'.
Making all in errors
make[1]: Nothing to be done for `all'.
Making all in doc
Making all in manuals
make[2]: Nothing to be done for `all'.
Making all in release-notes
make[2]: Nothing to be done for `all'.
make[2]: Nothing to be done for `all-am'.
Making all in helpers
Making all in basic_auth
Making all in DB
make[3]: Nothing to be done for `all'.
Making all in MSNT-multi-domain
make[3]: Nothing to be done for `all'.
Making all in NCSA
make[3]: Nothing to be done for `all'.
Making all in POP3
make[3]: Nothing to be done for `all'.
Making all in RADIUS
make[3]: Nothing to be done for `all'.
Making all in SMB
make[3]: Nothing to be done for `all'.
Making all in SMB_LM
/bin/sh ../../../libtool  --tag=CXX   --mode=link /Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-g++  -g -O2 -std=c++11  -L/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/sysroot/usr/lib -L/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/lib -o basic_smb_lm_auth msntauth.o valid.o ../../../lib/smblib/libsmblib.la ../../../lib/rfcnb/librfcnb.la ../../../lib/libmiscencoding.la ../../../compat/libcompat-squid.la  -lm 
libtool: link: /Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-g++ -g -O2 -std=c++11 -o basic_smb_lm_auth msntauth.o valid.o  -L/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/sysroot/usr/lib -L/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/lib ../../../lib/smblib/.libs/libsmblib.a ../../../lib/rfcnb/.libs/librfcnb.a ../../../lib/.libs/libmiscencoding.a ../../../compat/.libs/libcompat-squid.a -lm
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:535: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:535: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/locale_facets.h:869: error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/locale_facets.h:869: error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/locale_facets.h:869: error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:565: error: undefined reference to 'std::ostream::put(char)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:587: error: undefined reference to 'std::ostream::flush()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_ios.h:49: error: undefined reference to 'std::__throw_bad_cast()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_ios.h:49: error: undefined reference to 'std::cerr'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_ios.h:152: error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
msntauth.o(.ARM.extab.text._ZNSt6vectorI16domaincontrollerSaIS0_EED2Ev+0x0): error: undefined reference to '__gxx_personality_v0'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:249: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
msntauth.cc:56: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
msntauth.cc:56: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/vector.tcc:419: error: undefined reference to '__cxa_begin_catch'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/vector.tcc:426: error: undefined reference to '__cxa_rethrow'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/vector.tcc:419: error: undefined reference to '__cxa_end_catch'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/vector.tcc:419: error: undefined reference to '__cxa_end_cleanup'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ext/new_allocator.h:124: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
msntauth.o(.ARM.extab.text._ZNSt6vectorI16domaincontrollerSaIS0_EE19_M_emplace_back_auxIIRKS0_EEEvDpOT_+0x0): error: undefined reference to '__gxx_personality_v0'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:2208: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&, unsigned int, unsigned int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:583: error: undefined reference to 'std::string::swap(std::string&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:2208: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&, unsigned int, unsigned int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:583: error: undefined reference to 'std::string::swap(std::string&)'
msntauth.cc:56: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
msntauth.cc:56: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
msntauth.cc:97: error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
msntauth.cc:98: error: undefined reference to 'std::string::find(char, unsigned int) const'
msntauth.cc:99: error: undefined reference to 'std::string::find(char, unsigned int) const'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:535: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:2758: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/locale_facets.h:869: error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
msntauth.cc:107: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
msntauth.cc:108: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:113: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:324: error: undefined reference to 'std::__throw_out_of_range(char const*)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to '__cxa_end_cleanup'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_ios.h:49: error: undefined reference to 'std::__throw_bad_cast()'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator<char> const&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator<char> const&)'
msntauth.cc:115: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/ostream:113: error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/bits/basic_string.h:539: error: undefined reference to 'std::cerr'
/Users/ozojiegerald/Documents/toolchain/arm-linux-androideabi-4.8/include/c++/4.8/iostream:74: error: undefined reference to 'std::ios_base::Init::Init()'
msntauth.cc:61: error: undefined reference to 'std::ios_base::Init::~Init()'
msntauth.o(.ARM.extab.text.startup+0x0): error: undefined reference to '__gxx_personality_v0'
collect2: error: ld returned 1 exit status
make[3]: *** [basic_smb_lm_auth] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive] Error 1

更新:将我的ndk更新为android-ndk-r13b并且错误仍然存​​在

1 个答案:

答案 0 :(得分:1)

您应该尝试使用standalone toolchain。它们专门用于将NDK与非NDK构建系统一起使用。他们要做的工作是弄清楚如何传递你需要的所有旗帜;你只需要调用clang++

您还应该更新您的NDK。 r10现在已经三岁了。直到最近(r12,但你也可以升级到r13),独立的工具链并没有很好地工作。