I have C++ files in my iOS Xcode project. Those files uses the next libraries that I'm calling via HomeBrew:
mpg123/1.26.5
libgcrypt
ffmpeg
libgpg-error
fftw
libsndfile
The way I'm including them in the project is by setting the HeaderSearch Paths:
And the Library Search Paths:
That is all I'm doing to call those libraries. The error that I'm getting when I compile the project is the next one:
Undefined symbols for architecture x86_64:
"_mpg123_scan", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_mpg123_format_none", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_mpg123_length", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_mpg123_close", referenced from:
MP3InputStream::close() in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::ScopedMHandle::~ScopedMHandle() in mp3inputstream.o
"_fftwf_plan_dft_r2c_1d", referenced from:
fftar_float(unsigned long, float*, float*) in fft.o
"_fftwf_free", referenced from:
free_array_float(float*) in fft.o
"_mpg123_read", referenced from:
MP3InputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_fftwf_malloc", referenced from:
new_array_float(unsigned long) in fft.o
"_sf_readf_int", referenced from:
SFInputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in sfinputstream.o
"_mpg123_open", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_avformat_free_context", referenced from:
HLSOutputStream::close() in hlsoutputstream.o
"_mpg123_param", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_avio_open", referenced from:
HLSOutputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long, double, unsigned long) in hlsoutputstream.o
"_mpg123_delete", referenced from:
MP3InputStream::close() in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::ScopedMHandle::~ScopedMHandle() in mp3inputstream.o
"_avformat_write_header", referenced from:
HLSOutputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long, double, unsigned long) in hlsoutputstream.o
"_avcodec_free_context", referenced from:
HLSOutputStream::close_stream() in hlsoutputstream.o
"_swr_free", referenced from:
HLSOutputStream::close_stream() in hlsoutputstream.o
"_fftwf_plan_dft_c2r_1d", referenced from:
fftsr_float(unsigned long, float*, float*) in fft.o
"_swr_get_delay", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"_av_log", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"_mpg123_getformat", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_av_frame_make_writable", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"_fftwf_execute_dft_r2c", referenced from:
fftar_float(unsigned long, float*, float*) in fft.o
"_av_rescale_rnd", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"_swr_convert", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"ff_decode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, WavData&)", referenced from:
_main in testhls.o
"_avcodec_send_frame", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"_gcry_cipher_encrypt", referenced from:
Random::seed(unsigned long long, Random::Stream) in random.o
Random::refill_buffer() in random.o
"_av_strerror", referenced from:
av_make_error_string(char*, unsigned long, int) in hlsoutputstream.o
"_avcodec_open2", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_avio_closep", referenced from:
HLSOutputStream::close() in hlsoutputstream.o
"_av_dict_free", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_swr_alloc", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_sf_readf_float", referenced from:
SFInputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in sfinputstream.o
"VResampler::VResampler()", referenced from:
BufferedResamplerImpl<VResampler>::BufferedResamplerImpl(int, int, int) in wmadd.o
resample(WavData const&, int) in wmget.o
"_av_opt_set_int", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_sf_close", referenced from:
SFOutputStream::open(std::__1::function<SNDFILE_tag* (SF_INFO*)>, int, int, int, SFOutputStream::OutFormat) in sfoutputstream.o
SFOutputStream::close() in sfoutputstream.o
SFInputStream::close() in sfinputstream.o
SFInputStream::open(std::__1::function<SNDFILE_tag* (SF_INFO*)>) in sfinputstream.o
"_av_opt_set_sample_fmt", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_mpg123_format", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_swr_init", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_av_frame_get_buffer", referenced from:
HLSOutputStream::alloc_audio_frame(AVSampleFormat, unsigned long long, int, int, Error&) in hlsoutputstream.o
"_gcry_check_version", referenced from:
gcrypt_init() in random.o
"_av_interleaved_write_frame", referenced from:
HLSOutputStream::write_frame(AVRational const*, AVStream*, AVPacket*) in hlsoutputstream.o
"_av_packet_rescale_ts", referenced from:
HLSOutputStream::write_frame(AVRational const*, AVStream*, AVPacket*) in hlsoutputstream.o
"_av_frame_alloc", referenced from:
HLSOutputStream::alloc_audio_frame(AVSampleFormat, unsigned long long, int, int, Error&) in hlsoutputstream.o
"_avcodec_find_encoder", referenced from:
HLSOutputStream::add_stream(AVCodec**, AVCodecID) in hlsoutputstream.o
"Resampler::inpsize() const", referenced from:
BufferedResamplerImpl<Resampler>::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in wmadd.o
void process_resampler<Resampler>(Resampler&, std::__1::vector<float, std::__1::allocator<float> > const&, std::__1::vector<float, std::__1::allocator<float> >&) in wmget.o
"_av_dict_copy", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_avcodec_get_name", referenced from:
HLSOutputStream::add_stream(AVCodec**, AVCodecID) in hlsoutputstream.o
"_avcodec_alloc_context3", referenced from:
HLSOutputStream::add_stream(AVCodec**, AVCodecID) in hlsoutputstream.o
"_av_get_channel_layout", referenced from:
HLSOutputStream::add_stream(AVCodec**, AVCodecID) in hlsoutputstream.o
"_av_log_set_level", referenced from:
HLSOutputStream::HLSOutputStream(int, int, int) in hlsoutputstream.o
"_mpg123_strerror", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
MP3InputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in mp3inputstream.o
"_gcry_randomize", referenced from:
Random::gen_key() in random.o
"_gcry_cipher_close", referenced from:
Random::~Random() in random.o
"_gcry_strerror", referenced from:
Random::die_on_error(char const*, unsigned int) in random.o
"_gcry_cipher_setctr", referenced from:
Random::seed(unsigned long long, Random::Stream) in random.o
"Resampler::setup(unsigned int, unsigned int, unsigned int, unsigned int)", referenced from:
create_resampler(int, int, int) in wmadd.o
resample(WavData const&, int) in wmget.o
"_fftwf_execute_dft_c2r", referenced from:
fftsr_float(unsigned long, float*, float*) in fft.o
"_gcry_strsource", referenced from:
Random::die_on_error(char const*, unsigned int) in random.o
"_avformat_alloc_output_context2", referenced from:
HLSOutputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long, double, unsigned long) in hlsoutputstream.o
"_gcry_cipher_setkey", referenced from:
Random::Random(unsigned long long, Random::Stream) in random.o
"_avcodec_parameters_from_context", referenced from:
HLSOutputStream::open_audio(AVCodec*, AVDictionary*) in hlsoutputstream.o
"_sf_open_virtual", referenced from:
SFOutputStream::open(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >*, int, int, int, SFOutputStream::OutFormat)::$_1::operator()(SF_INFO*) const in sfoutputstream.o
SFInputStream::open(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const*)::$_1::operator()(SF_INFO*) const in sfinputstream.o
"_av_rescale_q", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"_sf_strerror", referenced from:
SFOutputStream::open(std::__1::function<SNDFILE_tag* (SF_INFO*)>, int, int, int, SFOutputStream::OutFormat) in sfoutputstream.o
SFOutputStream::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in sfoutputstream.o
SFInputStream::open(std::__1::function<SNDFILE_tag* (SF_INFO*)>) in sfinputstream.o
SFInputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in sfinputstream.o
"_mpg123_outblock", referenced from:
MP3InputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_sf_error", referenced from:
SFOutputStream::open(std::__1::function<SNDFILE_tag* (SF_INFO*)>, int, int, int, SFOutputStream::OutFormat) in sfoutputstream.o
SFOutputStream::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in sfoutputstream.o
SFInputStream::open(std::__1::function<SNDFILE_tag* (SF_INFO*)>) in sfinputstream.o
SFInputStream::read_frames(std::__1::vector<float, std::__1::allocator<float> >&, unsigned long) in sfinputstream.o
"_gcry_cipher_open", referenced from:
Random::Random(unsigned long long, Random::Stream) in random.o
"_mpg123_rates", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"_av_init_packet", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"VResampler::inpsize() const", referenced from:
BufferedResamplerImpl<VResampler>::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in wmadd.o
void process_resampler<VResampler>(VResampler&, std::__1::vector<float, std::__1::allocator<float> > const&, std::__1::vector<float, std::__1::allocator<float> >&) in wmget.o
"_sf_open", referenced from:
SFOutputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int, SFOutputStream::OutFormat)::$_0::operator()(SF_INFO*) const in sfoutputstream.o
SFInputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0::operator()(SF_INFO*) const in sfinputstream.o
"_av_opt_set", referenced from:
HLSOutputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long, double, unsigned long) in hlsoutputstream.o
"Resampler::process()", referenced from:
BufferedResamplerImpl<Resampler>::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in wmadd.o
void process_resampler<Resampler>(Resampler&, std::__1::vector<float, std::__1::allocator<float> > const&, std::__1::vector<float, std::__1::allocator<float> >&) in wmget.o
"VResampler::process()", referenced from:
BufferedResamplerImpl<VResampler>::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in wmadd.o
void process_resampler<VResampler>(VResampler&, std::__1::vector<float, std::__1::allocator<float> > const&, std::__1::vector<float, std::__1::allocator<float> >&) in wmget.o
"_mpg123_init", referenced from:
mp3_init() in mp3inputstream.o
"_av_get_channel_layout_nb_channels", referenced from:
HLSOutputStream::add_stream(AVCodec**, AVCodecID) in hlsoutputstream.o
"_gcry_control", referenced from:
gcrypt_init() in random.o
"_sf_writef_int", referenced from:
SFOutputStream::write_frames(std::__1::vector<float, std::__1::allocator<float> > const&) in sfoutputstream.o
"Resampler::~Resampler()", referenced from:
BufferedResamplerImpl<Resampler>::~BufferedResamplerImpl() in wmadd.o
resample(WavData const&, int) in wmget.o
"_avformat_new_stream", referenced from:
HLSOutputStream::add_stream(AVCodec**, AVCodecID) in hlsoutputstream.o
"_av_write_trailer", referenced from:
HLSOutputStream::close() in hlsoutputstream.o
"VResampler::~VResampler()", referenced from:
BufferedResamplerImpl<VResampler>::~BufferedResamplerImpl() in wmadd.o
resample(WavData const&, int) in wmget.o
"_av_frame_free", referenced from:
HLSOutputStream::close_stream() in hlsoutputstream.o
"_avcodec_receive_packet", referenced from:
HLSOutputStream::write_audio_frame(Error&) in hlsoutputstream.o
"Resampler::Resampler()", referenced from:
BufferedResamplerImpl<Resampler>::BufferedResamplerImpl(int, int, int) in wmadd.o
resample(WavData const&, int) in wmget.o
"_mpg123_new", referenced from:
MP3InputStream::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
MP3InputStream::detect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mp3inputstream.o
"VResampler::setup(double, unsigned int, unsigned int)", referenced from:
create_resampler(int, int, int) in wmadd.o
resample(WavData const&, int) in wmget.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Since you've installed this using brew you are trying to link against libraries built for the Mac. You need to build those libraries for iOS. Note this will typically involve making a fat binary of the different architectures you'll need per library. You can easily test this for fftw and see if the linker errors disappear. Here are some references to build or download a pre-built version.
https://github.com/godock/fftw-build
In theory once you link up against the iOS version, you should see errors like
_fftwf_plan_dft_r2c_1d", referenced from:
fftar_float(unsigned long, float*, float*) in fft.o
_fftwf_free", referenced from:
free_array_float(float*) in fft.o
disappear. You can also pick another one of your libraries to replace with the iOS version to test. For example ffmpeg build instructions can be found here.
https://github.com/kewlbear/FFmpeg-iOS-build-script
You'll unfortunately have to hunt down how to build them all.
Related
I have downloaded the whole Boost source from https://www.boost.org/doc/libs/1_72_0/libs/regex/doc/html/index.html and I have the instructions of installation:
tar -vcf boost_1_76_0.tar
./bootstrap.sh --with-toolset=clang --with-libraries=program_options,regex,filesystem,system
./b2
sudo ./b2 install
Then I got a message that everything has been successfully installed:
The following directory should be added to compiler include paths:
/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0
The following directory should be added to linker library paths:
/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib
Now, I have a code where I load the Boost regex header:
#include <boost/regex.hpp>
[More code...]
And now the problem is with library linking, I have tried to compile with:
gcc -I/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0 -L/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib -O3 -o readvcf readvcf.cc -lboost_regex
(Not sure if I should use -lboost_regex but that's something I found in the internet).
And this fails horribly with ...
Undefined symbols for architecture x86_64:
"std::logic_error::what() const", referenced from:
vtable for boost::wrapexcept<std::invalid_argument> in readvcf-3b61f4.o
vtable for boost::wrapexcept<std::logic_error> in readvcf-3b61f4.o
"std::runtime_error::what() const", referenced from:
vtable for boost::wrapexcept<std::runtime_error> in readvcf-3b61f4.o
vtable for boost::regex_error in readvcf-3b61f4.o
vtable for boost::wrapexcept<boost::regex_error> in readvcf-3b61f4.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
char* boost::re_detail_500::re_is_set_member<char*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(char*, char*, boost::re_detail_500::re_set_long<unsigned int> const*, boost::re_detail_500::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in readvcf-3b61f4.o
std::__1::__wrap_iter<char const*> boost::re_detail_500::re_is_set_member<std::__1::__wrap_iter<char const*>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(std::__1::__wrap_iter<char const*>, std::__1::__wrap_iter<char const*>, boost::re_detail_500::re_set_long<unsigned int> const*, boost::re_detail_500::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in readvcf-3b61f4.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const", referenced from:
unsigned int boost::re_detail_500::find_sort_syntax<boost::re_detail_500::cpp_regex_traits_implementation<char>, char>(boost::re_detail_500::cpp_regex_traits_implementation<char> const*, char*) in readvcf-3b61f4.o
boost::re_detail_500::lookup_default_collate_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in readvcf-3b61f4.o
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
VCF2SNP(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, int) in readvcf-3b61f4.o
boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_open_paren() in readvcf-3b61f4.o
boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_alt() in readvcf-3b61f4.o
boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_perl_extension() in readvcf-3b61f4.o
void boost::re_detail_500::named_subexpressions::set_name<char>(char const*, char const*, int) in readvcf-3b61f4.o
boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_set_literal(boost::re_detail_500::basic_char_set<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >&) in readvcf-3b61f4.o
boost::re_detail_500::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::create_startmaps(boost::re_detail_500::re_syntax_base*) in readvcf-3b61f4.o
...
"std::__1::__vector_base_common<true>::__throw_out_of_range() const", referenced from:
boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_open_paren() in readvcf-3b61f4.o
boost::re_detail_500::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_perl_extension() in readvcf-3b61f4.o
"std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
boost::re_detail_500::cpp_regex_traits_char_layer<char>::init() in readvcf-3b61f4.o
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in readvcf-3b61f4.o
boost::re_detail_500::cpp_regex_traits_implementation<char>::lookup_classname(char const*, char const*) const in readvcf-3b61f4.o
boost::re_detail_500::cpp_regex_traits_implementation<char>::lookup_classname_imp(char const*, char const*) const in readvcf-3b61f4.o
boost::re_detail_500::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const in readvcf-3b61f4.o
boost::re_detail_500::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in readvcf-3b61f4.o
boost::re_detail_500::lookup_default_collate_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in readvcf-3b61f4.o
...
"std::__1::locale::has_facet(std::__1::locale::id&) const", referenced from:
boost::re_detail_500::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in readvcf-3b61f4.o
std::__1::basic_filebuf<char, std::__1::char_traits<char> >::basic_filebuf() in readvcf-3b61f4.o
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
getAlleles(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<std::__1::vector<bool, std::__1::allocator<bool> >, std::__1::allocator<std::__1::vector<bool, std::__1::allocator<bool> > > >&, int) in readvcf-3b61f4.o
VCF2SNP(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int, int) in readvcf-3b61f4.o
std::__1::basic_filebuf<char, std::__1::char_traits<char> >::imbue(std::__1::locale const&) in readvcf-3b61f4.o
boost::re_detail_500::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in readvcf-3b61f4.o
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in readvcf-3b61f4.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in readvcf-3b61f4.o
std::__1::basic_filebuf<char, std::__1::char_traits<char> >::basic_filebuf() in readvcf-3b61f4.o
...
And much more. Up to:
_main in readvcf-3b61f4.o
std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_istringstream() in readvcf-3b61f4.o
virtual thunk to std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_istringstream() in readvcf-3b61f4.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have run out of ideas and I cannot find any solution. Please, any help would be really appreciated! Thank you in advance
You are using GCC to build a c++ program, so we get these linkage errors. The g++ tool is used to build a c++ program, it automatically adds the standard library linkage for you.
Can be fixed by
use g++
g++ -I/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0 -L/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib -O3 -o readvcf readvcf.cc -lboost_rege
use GCC with the additional option (Strongly not recommended)
gcc -x c++ -I/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0 -L/Users/3omni/Documents/GitHub/PERSONAL/GEN/boost_1_76_0/stage/lib -O3 -o readvcf readvcf.cc -lboost_regex -lstdc++
Related question:undefined reference to __cxa_end_cleanup'
When I link a dynamic library with CMake, create the make file and then use make, it compiles and builds correctly.
When I link a static library, CMake doesn't complain but when I run make, it throws a linker error at me, even though all I did was replace the .dylib with a .a of the same name.
This is my CMake file linking to a static library:
cmake_minimum_required (VERSION 3.0)
add_executable (TEST main.cpp)
include_directories ("${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/include")
target_link_libraries (TEST "${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/lib/libpqxx.a")
Any ideas?
Output for cmake:
>> cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/john/Documents/Test/src
Output for make:
>> make
[ 33%] Linking CXX executable TEST
Undefined symbols for architecture x86_64:
"_PQbackendPID", referenced from:
pqxx::connection_base::backendpid() const in libpqxx.a(connection_base.o)
"_PQcancel", referenced from:
pqxx::connection_base::cancel_query() in libpqxx.a(connection_base.o)
"_PQclear", referenced from:
pqxx::internal::clear_result(pg_result const*) in libpqxx.a(result.o)
"_PQclientEncoding", referenced from:
pqxx::connection_base::encoding_code() in libpqxx.a(connection_base.o)
"_PQcmdStatus", referenced from:
pqxx::result::cmd_status() const in libpqxx.a(result.o)
"_PQcmdTuples", referenced from:
pqxx::result::affected_rows() const in libpqxx.a(result.o)
"_PQconnectPoll", referenced from:
pqxx::connect_async::do_completeconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQconnectStart", referenced from:
pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQconnectdb", referenced from:
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQconsumeInput", referenced from:
pqxx::connection_base::consume_input() in libpqxx.a(connection_base.o)
"_PQdb", referenced from:
pqxx::connection_base::dbname() in libpqxx.a(connection_base.o)
"_PQencryptPassword", referenced from:
pqxx::encrypt_password(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQendcopy", referenced from:
pqxx::connection_base::write_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQerrorMessage", referenced from:
pqxx::connection_base::err_msg() const in libpqxx.a(connection_base.o)
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_direct::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_async::do_completeconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQescapeByteaConn", referenced from:
pqxx::connection_base::esc_raw(unsigned char const*, unsigned long) in libpqxx.a(connection_base.o)
"_PQescapeIdentifier", referenced from:
pqxx::connection_base::quote_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQescapeStringConn", referenced from:
pqxx::connection_base::esc(char const*, unsigned long) in libpqxx.a(connection_base.o)
"_PQexec", referenced from:
pqxx::connection_base::exec(char const*, int) in libpqxx.a(connection_base.o)
pqxx::connection_base::add_receiver(pqxx::notification_receiver*) in libpqxx.a(connection_base.o)
"_PQexecParams", referenced from:
pqxx::connection_base::parameterized_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const* const*, int const*, int const*, int) in libpqxx.a(connection_base.o)
pqxx::connection_base::exec_params(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pqxx::internal::params const&) in libpqxx.a(connection_base.o)
"_PQexecPrepared", referenced from:
pqxx::connection_base::prepared_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const* const*, int const*, int const*, int) in libpqxx.a(connection_base.o)
pqxx::connection_base::exec_prepared(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, pqxx::internal::params const&) in libpqxx.a(connection_base.o)
"_PQfinish", referenced from:
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connectionpolicy::do_disconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQfname", referenced from:
pqxx::result::column_name(unsigned int) const in libpqxx.a(result.o)
"_PQfnumber", referenced from:
pqxx::result::column_number(char const*) const in libpqxx.a(row.o)
"_PQfreeCancel", referenced from:
(anonymous namespace)::cancel_wrapper::~cancel_wrapper() in libpqxx.a(connection_base.o)
"_PQfreemem", referenced from:
pqxx::internal::freepqmem(void const*) in libpqxx.a(util.o)
"_PQftable", referenced from:
pqxx::result::column_table(unsigned int) const in libpqxx.a(result.o)
"_PQftablecol", referenced from:
pqxx::result::table_column(unsigned int) const in libpqxx.a(result.o)
"_PQftype", referenced from:
pqxx::result::column_type(unsigned int) const in libpqxx.a(result.o)
"_PQgetCancel", referenced from:
pqxx::connection_base::cancel_query() in libpqxx.a(connection_base.o)
"_PQgetCopyData", referenced from:
pqxx::connection_base::read_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libpqxx.a(connection_base.o)
"_PQgetResult", referenced from:
pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
pqxx::connection_base::read_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libpqxx.a(connection_base.o)
pqxx::connection_base::end_copy_write() in libpqxx.a(connection_base.o)
pqxx::connection_base::get_result() in libpqxx.a(connection_base.o)
"_PQgetisnull", referenced from:
pqxx::result::get_is_null(unsigned long, unsigned int) const in libpqxx.a(result.o)
"_PQgetlength", referenced from:
pqxx::result::get_length(unsigned long, unsigned int) const in libpqxx.a(result.o)
"_PQgetvalue", referenced from:
pqxx::result::GetValue(unsigned long, unsigned int) const in libpqxx.a(result.o)
"_PQhost", referenced from:
pqxx::connection_base::hostname() in libpqxx.a(connection_base.o)
"_PQisBusy", referenced from:
pqxx::connection_base::is_busy() const in libpqxx.a(connection_base.o)
"_PQisthreadsafe", referenced from:
pqxx::describe_thread_safety() in libpqxx.a(util.o)
"_PQnfields", referenced from:
pqxx::result::columns() const in libpqxx.a(result.o)
"_PQnotifies", referenced from:
pqxx::connection_base::get_notifs() in libpqxx.a(connection_base.o)
"_PQntuples", referenced from:
pqxx::result::size() const in libpqxx.a(result.o)
pqxx::result::empty() const in libpqxx.a(result.o)
"_PQoidValue", referenced from:
pqxx::result::inserted_oid() const in libpqxx.a(result.o)
"_PQport", referenced from:
pqxx::connection_base::port() in libpqxx.a(connection_base.o)
"_PQprepare", referenced from:
pqxx::connection_base::register_prepared(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQprotocolVersion", referenced from:
pqxx::connection_base::protocol_version() const in libpqxx.a(connection_base.o)
"_PQputCopyData", referenced from:
pqxx::connection_base::write_copy_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQputCopyEnd", referenced from:
pqxx::connection_base::end_copy_write() in libpqxx.a(connection_base.o)
"_PQreset", referenced from:
pqxx::connection_base::reset() in libpqxx.a(connection_base.o)
"_PQresultErrorField", referenced from:
pqxx::result::ThrowSQLError(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in libpqxx.a(result.o)
pqxx::result::errorposition() const in libpqxx.a(result.o)
"_PQresultErrorMessage", referenced from:
pqxx::result::StatusError() const in libpqxx.a(result.o)
"_PQresultStatus", referenced from:
pqxx::result::StatusError() const in libpqxx.a(result.o)
"_PQsendQuery", referenced from:
pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
pqxx::connection_base::start_exec(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libpqxx.a(connection_base.o)
"_PQserverVersion", referenced from:
pqxx::connection_base::read_capabilities() in libpqxx.a(connection_base.o)
"_PQsetErrorVerbosity", referenced from:
pqxx::connection_base::set_verbosity(pqxx::connection_base::error_verbosity) in libpqxx.a(connection_base.o)
"_PQsetNoticeProcessor", referenced from:
pqxx::connection_base::set_up_state() in libpqxx.a(connection_base.o)
pqxx::connection_base::close() in libpqxx.a(connection_base.o)
"_PQsocket", referenced from:
(anonymous namespace)::socket_of(pg_conn const*) in libpqxx.a(connection_base.o)
"_PQstatus", referenced from:
pqxx::connection_base::status() const in libpqxx.a(connection_base.o)
pqxx::connectionpolicy::normalconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_direct::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
pqxx::connect_async::do_startconnect(pg_conn*) in libpqxx.a(connection.o)
"_PQtrace", referenced from:
pqxx::connection_base::internal_set_trace() in libpqxx.a(connection_base.o)
"_PQunescapeBytea", referenced from:
pqxx::connection_base::unesc_raw(char const*) in libpqxx.a(connection_base.o)
"_PQuntrace", referenced from:
pqxx::connection_base::internal_set_trace() in libpqxx.a(connection_base.o)
"_PQuser", referenced from:
pqxx::connection_base::username() in libpqxx.a(connection_base.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [TEST] Error 1
make[1]: *** [CMakeFiles/TEST.dir/all] Error 2
make: *** [all] Error 2
if you send error messages it'd be better , but try this:
link_directories(${CMAKE_SOURCE_DIR}/Dependencies/libpqxx/lib)
target_link_libraries (TEST pqxx)
I've figured it out. I was just missing some dependencies for the pqxx library. I've added a reference to libpq.a, libssl.a, and libcrypto.a as well as their include/ directories and it ended up working. I guess .dylib files link to dependencies by themselves but you have to manually include them with static libraries?
I have been following many other answers here on StackOverflow and other resources, but I can't get clang to work with boost 1.63 on macOS. Simply installed boost:
./bootstrap.sh --prefix=/usr/local
./b2 cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
Now. Im just doing the following:
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main()
{
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
}
This gives me:
clang++ \
-g -Wall -Wextra \
-std=c++14 \
-stdlib=libc++ \
-I /usr/local/include \
-L /usr/local/lib \
./src/main.cpp \
-o ./src/tool.o
Undefined symbols for architecture x86_64:
"boost::program_options::validators::check_first_occurrence(boost::any const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in main-afe96c.o
"boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)", referenced from:
boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) in main-afe96c.o
"boost::program_options::options_description::add_options()", referenced from:
_main in main-afe96c.o
"boost::program_options::options_description::m_default_line_length", referenced from:
_main in main-afe96c.o
"boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
_main in main-afe96c.o
"boost::program_options::invalid_option_value::invalid_option_value(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::vector<int, std::__1::allocator<int> >*, int) in main-afe96c.o
void boost::program_options::validate<int, char>(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, int*, long) in main-afe96c.o
"boost::program_options::error_with_option_name::error_with_option_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) in main-afe96c.o
"boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)", referenced from:
_main in main-afe96c.o
"boost::program_options::options_description_easy_init::operator()(char const*, char const*)", referenced from:
_main in main-afe96c.o
"boost::program_options::arg", referenced from:
boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char>::name() const in main-afe96c.o
"boost::program_options::error_with_option_name::substitute_placeholders(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in main-afe96c.o
vtable for boost::program_options::validation_error in main-afe96c.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in main-afe96c.o
vtable for boost::program_options::invalid_option_value in main-afe96c.o
"boost::program_options::error_with_option_name::what() const", referenced from:
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in main-afe96c.o
vtable for boost::program_options::validation_error in main-afe96c.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in main-afe96c.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in main-afe96c.o
vtable for boost::program_options::invalid_option_value in main-afe96c.o
"boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) const", referenced from:
vtable for boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char> in main-afe96c.o
"typeinfo for boost::program_options::error_with_option_name", referenced from:
typeinfo for boost::program_options::validation_error in main-afe96c.o
"typeinfo for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
typeinfo for boost::program_options::typed_value<std::__1::vector<int, std::__1::allocator<int> >, char> in main-afe96c.o
"vtable for boost::program_options::error_with_option_name", referenced from:
boost::program_options::error_with_option_name::error_with_option_name(boost::program_options::error_with_option_name const&) in main-afe96c.o
boost::program_options::error_with_option_name::~error_with_option_name() in main-afe96c.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper() in main-afe96c.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [annorna] Error 1
However, adding -l boost_system does not work. What is the solution to get boost going? Is the path wrong? OR do I need some other flag?
So I have a mini OpenGL project that I am doing in C++ in Xcode. I am using several libraries including the SOIL and GLEW libraries, their respective header files, and the SDL2, OpenGL, and Corefoundation frameworks. The project builds just fine in Xcode with the following compiler options: C++ Language Dialect set to -std=c++11 and C++ Standard Library set to libc++. However, when I try to build this project with clang on the command line, with the following command:
clang++ -stdlib=libc++ -std=c++11
-I/usr/local/include/SOIL/src
-I/usr/local/include/glm/glm
-I/usr/local/include/glew-1.10.0/include/
-framework SDL2
-framework CoreFoundation
-framework OpenGL
-L/usr/local/include/glew-1.10.0/lib/
-L/usr/local/lib
main.cpp euchre.cpp euchre.h (These 3 files are in the same directory)
I get the following errors:
Undefined symbols for architecture x86_64:
"_SOIL_free_image_data", referenced from:
Euchre::MakeObject::LoadTexture(char const*, int) in euchre-d6b330.o
"_SOIL_load_image", referenced from:
Euchre::MakeObject::LoadTexture(char const*, int) in euchre-d6b330.o
"___glewActiveTexture", referenced from:
Euchre::MakeObject::LoadTexture(char const*, int) in euchre-d6b330.o
"___glewAttachShader", referenced from:
Euchre::MakeObject::LoadShaders(char const*, char const*) in euchre-d6b330.o
"___glewBindBuffer", referenced from:
Euchre::MakeObject::makeAttribute(unsigned int, char const*, unsigned int, unsigned int, int, unsigned int, unsigned char, int, void const*) in euchre-d6b330.o
unsigned int Euchre::MakeObject::makeBufferObject<float>(int, unsigned int, unsigned int, std::__1::vector<float, std::__1::allocator<float> >) in euchre-d6b330.o
unsigned int Euchre::MakeObject::makeBufferObject<unsigned int>(int, unsigned int, unsigned int, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >) in euchre-d6b330.o
"___glewBindVertexArray", referenced from:
_main in main-6799fc.o
"___glewBufferData", referenced from:
unsigned int Euchre::MakeObject::makeBufferObject<float>(int, unsigned int, unsigned int, std::__1::vector<float, std::__1::allocator<float> >) in euchre-d6b330.o
unsigned int Euchre::MakeObject::makeBufferObject<unsigned int>(int, unsigned int, unsigned int, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >) in euchre-d6b330.o
"___glewCompileShader", referenced from:
Euchre::MakeObject::compileShader(unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in euchre-d6b330.o
"___glewCreateProgram", referenced from:
Euchre::MakeObject::LoadShaders(char const*, char const*) in euchre-d6b330.o
"___glewCreateShader", referenced from:
Euchre::MakeObject::LoadShaders(char const*, char const*) in euchre-d6b330.o
"___glewDeleteBuffers", referenced from:
_main in main-6799fc.o
"___glewDeleteProgram", referenced from:
_main in main-6799fc.o
"___glewDeleteShader", referenced from:
Euchre::MakeObject::LoadShaders(char const*, char const*) in euchre-d6b330.o
"___glewDeleteVertexArrays", referenced from:
_main in main-6799fc.o
"___glewEnableVertexAttribArray", referenced from:
Euchre::MakeObject::makeAttribute(unsigned int, char const*, unsigned int, unsigned int, int, unsigned int, unsigned char, int, void const*) in euchre-d6b330.o
"___glewGenBuffers", referenced from:
unsigned int Euchre::MakeObject::makeBufferObject<float>(int, unsigned int, unsigned int, std::__1::vector<float, std::__1::allocator<float> >) in euchre-d6b330.o
unsigned int Euchre::MakeObject::makeBufferObject<unsigned int>(int, unsigned int, unsigned int, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >) in euchre-d6b330.o
"___glewGenVertexArrays", referenced from:
Euchre::MakeObject::makeVertexArrayObject(int) in euchre-d6b330.o
"___glewGetAttribLocation", referenced from:
Euchre::MakeObject::makeAttribute(unsigned int, char const*, unsigned int, unsigned int, int, unsigned int, unsigned char, int, void const*) in euchre-d6b330.o
"___glewGetShaderiv", referenced from:
Euchre::MakeObject::compileShader(unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in euchre-d6b330.o
"___glewLinkProgram", referenced from:
Euchre::MakeObject::LoadShaders(char const*, char const*) in euchre-d6b330.o
"___glewShaderSource", referenced from:
Euchre::MakeObject::compileShader(unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in euchre-d6b330.o
"___glewUseProgram", referenced from:
_main in main-6799fc.o
"___glewVertexAttribPointer", referenced from:
Euchre::MakeObject::makeAttribute(unsigned int, char const*, unsigned int, unsigned int, int, unsigned int, unsigned char, int, void const*) in euchre-d6b330.o
"_glewExperimental", referenced from:
_main in main-6799fc.o
"_glewInit", referenced from:
_main in main-6799fc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What I don't understand is how I am compiling with the same settings as on Xcode, but in terminal, I can't get this to work.
I'm trying to compile some C++ code (including C++11 features) on OS X 10.8 using the clang++ compiler. I have a makefile that generates the object files OK, then on the command:
clang++ -o Analysis.so -shared DataFile.o CR39DataFile.o
I get tons of errors about symbol(s) not found for architecture x86_64. The code works fine on a *nix system using g++ and changing the compiler flags appropriately for C++11 support. To compile the *.o I am doing it like:
clang++ -c -Wall -std=c++11 -stdlib=libc++ -I../src ../src/DataFile.cc
Edit: output of the linking command is:
clang++ -o Analysis.so -shared DataFile.o CR39DataFile.o
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char const*, unsigned long, unsigned long) const", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
CR39DataFile::trim(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
std::__1::vector<frame*, std::__1::allocator<frame*> >::__append(unsigned long) in CR39DataFile.o
std::__1::vector<std::__1::vector<frame*, std::__1::allocator<frame*> >*, std::__1::allocator<std::__1::vector<frame*, std::__1::allocator<frame*> >*> >::__append(unsigned long) in CR39DataFile.o
"std::__1::__vector_base_common<true>::__throw_out_of_range() const", referenced from:
std::__1::vector<std::__1::vector<frame*, std::__1::allocator<frame*> >*, std::__1::allocator<std::__1::vector<frame*, std::__1::allocator<frame*> >*> >::at(unsigned long) in CR39DataFile.o
std::__1::vector<frame*, std::__1::allocator<frame*> >::at(unsigned long) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::erase(unsigned long, unsigned long)", referenced from:
CR39DataFile::trim(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*)", referenced from:
CR39DataFile::CR39DataFile() in CR39DataFile.o
CR39DataFile::clear() in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::insert(unsigned long, unsigned long, char)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::resize(unsigned long, char)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
DataFile::read(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
DataFile::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
std::__1::thread::thread<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void>(bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)&&, DataFile*&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in DataFile.o
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
CR39DataFile::write_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
CR39DataFile::write_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, float, float, float, float, float, float, float, float) in CR39DataFile.o
CR39DataFile::write_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, float, float, float, float, float) in CR39DataFile.o
...
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long, std::__1::allocator<char> const&)", referenced from:
CR39DataFile::read_thread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
DataFile::~DataFile() in DataFile.o
DataFile::read(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
DataFile::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) in DataFile.o
std::__1::thread::thread<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void>(bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)&&, DataFile*&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in DataFile.o
void* std::__1::__thread_proxy<std::__1::tuple<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*) in DataFile.o
std::__1::__tuple_leaf<2ul, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false>::~__tuple_leaf() in DataFile.o
CR39DataFile::CR39DataFile() in CR39DataFile.o
...
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
CR39DataFile::set_file_path(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
CR39DataFile::set_file_auxpath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in CR39DataFile.o
"std::__1::__thread_struct::__thread_struct()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*) in DataFile.o
"std::__1::__thread_struct::~__thread_struct()", referenced from:
std::__1::__thread_specific_ptr<std::__1::__thread_struct>::reset(std::__1::__thread_struct*) in DataFile.o
"std::__1::__thread_local_data()", referenced from:
void* std::__1::__thread_proxy<std::__1::tuple<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*) in DataFile.o
"std::__1::__throw_system_error(int, char const*)", referenced from:
std::__1::thread::thread<bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), DataFile*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void>(bool (DataFile::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)&&, DataFile*&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&) in DataFile.o
"std::__1::thread::~thread()", referenced from:
DataFile::cleanup_file_io() in DataFile.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Analysis.so] Error 1
I suspect this issue is because of the two C++ runtime libraries available under OS X. Use the following to link the dynamic library:
clang++ -stdlib=libc++ -o Analysis.dylib -shared DataFile.o CR39DataFile.o
(the -stdlib=libc++ being the key difference). I think the default C++ runtime is the GNU implementation which is confusing the linker as you compiled with the libc++ implementation.
As a side note, faced with the same error message, I discovered I needed to use gcc -lstdc++ -lLibraryName ... (the stdc++ part being needed).
See also https://github.com/JonathanSalwan/Triton/issues/243