簡體   English   中英

在 iOS Xcode 項目中運行 C++ 庫時出錯

[英]Error when running C++ libraries in iOS Xcode Project

我的 iOS Xcode 項目中有 C++ 文件。 這些文件使用我通過 HomeBrew 調用的下一個庫:

  • mpg123/1.26.5
  • libgcrypt
  • ffmpeg
  • libgpg 錯誤
  • fftw
  • 庫文件

我將它們包含在項目中的方式是設置 HeaderSearch 路徑: 在此處輸入圖像描述

和圖書館搜索路徑: 在此處輸入圖像描述

這就是我調用這些庫所做的一切。 我在編譯項目時遇到的錯誤是下一個:

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)

由於您使用brew安裝了它,因此您正在嘗試鏈接為 Mac 構建的庫。 您需要為 iOS 構建這些庫。 請注意,這通常涉及制作每個庫所需的不同架構的胖二進制文件。 您可以輕松地對此進行fftw測試,並查看 linker 錯誤是否消失。 以下是構建或下載預構建版本的一些參考。

https://github.com/godock/fftw-build

理論上,一旦您鏈接到 iOS 版本,您應該會看到如下錯誤

_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

消失。 您還可以選擇另一個庫替換為 iOS 版本進行測試。 例如ffmpeg構建指令可以在這里找到。

https://github.com/kewlbear/FFmpeg-iOS-build-script

不幸的是,您將不得不尋找如何構建它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM