Undefined Symbols when Linking Static Library

273 views
Skip to first unread message

Victor Stewart

unread,
May 16, 2020, 1:38:33 AM5/16/20
to Protocol Buffers
Hey having an absolutely miserable time trying to cross compile libphonenumber, which depends on protobuf, into a static library.

Everything compiles. But fails with undefined symbols at linking time.

this is how I'm building protobuf, on x86 with an x86 protoc that I built first.

file libraries/protoc 

libraries/protoc: Mach-O 64-bit executable x86_64


///////////////////////////////////////////////////////////////////


export build_dir=`pwd`/cpp-build

export darwin=darwin`uname -r`

export protoc=/usr/local/bin/protoc

export isysroot=`xcrun --sdk iphoneos --show-sdk-path`

export cflags="-Wno-unused-local-typedef -Wno-unused-function -DNDEBUG -g -O3 -pipe -fPIC -fcxx-exceptions"

export cxxflags="$cflags -std=c++17 -stdlib=libc++"


mkdir -p $build_dir/arch

mkdir -p $build_dir/lib


./configure \

--build=x86_64-apple-$darwin \

--host=arm \

--with-protoc=$protoc \

--disable-shared \

--prefix=/usr/local \

"CC=clang" \

"CFLAGS=$cflags -miphoneos-version-min=12.0 -arch arm64 -isysroot $isysroot" \

"CXX=clang" \

"CXXFLAGS=$cxxflags -miphoneos-version-min=12.0 -arch arm64 -isysroot $isysroot" \

LDFLAGS="-arch arm64 -miphoneos-version-min=12.0 -stdlib=libc++" \

"LIBS=-lc++ -lc++abi"


make -j8

make install


///////////////////////////////////////////////////////////////////


lipo -info libprotobuf.a

Non-fat file: libprotobuf.a is architecture: arm64


lipo -info Release-iphoneos/libphonenumber.a

Non-fat file: Release-iphoneos/libphonenumber.a is architecture: arm64


Undefined symbols for architecture arm64:

  "google::protobuf::internal::LogMessage::operator<<(char const*)", referenced from:

      ____ZN13ContactReaper14gatherContactsEv_block_invoke in xxx_lto.o

      google::protobuf::internal::ArenaStringPtr::CreateInstance(google::protobuf::Arena*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const*) in xxx_lto.o

  "google::protobuf::internal::LogMessage::~LogMessage()", referenced from:

      ____ZN13ContactReaper14gatherContactsEv_block_invoke in xxx_lto.o

      google::protobuf::internal::ArenaStringPtr::CreateInstance(google::protobuf::Arena*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const*) in xxx_lto.o

  "google::protobuf::internal::ReadSizeFallback(char const*, unsigned int)", referenced from:

      i18n::phonenumbers::PhoneMetadata::_InternalParse(char const*, google::protobuf::internal::ParseContext*) in libphonenumber.a(phonemetadata.pb.o)

      i18n::phonenumbers::PhoneMetadataCollection::_InternalParse(char const*, google::protobuf::internal::ParseContext*) in libphonenumber.a(phonemetadata.pb.o)


etc... 41 of them.


been at this for 2 days, and for the life of me can't figure out how to fix it.


has anyone else made it through this alive?

Santosh Passoubady (Sansan)

unread,
Aug 16, 2023, 7:16:49 PM8/16/23
to Protocol Buffers
Did you ever figured?
Reply all
Reply to author
Forward
0 new messages