c – .mm转换导致架构i386错误的未定义符号

前端之家收集整理的这篇文章主要介绍了c – .mm转换导致架构i386错误的未定义符号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最近将一个c文件导入到我想要使用的obj项目中.在我想要使用它的类中,我将文件名从MyClass.m更改为MyClass.mm.

这样做会给我20个左右的错误.这些错误到底意味着什么?如何将MyClass更改为目标c类以方便我想要使用的新c类,而不会出现这些错误

Undefined symbols for architecture i386:
  "setAudioInputIsStereo(audiosourceobj*,bool)",referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
  "setAudioInputFrameCount(audiosourceobj*,int)",referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
  "setAudioInputSendValue(audiosourceobj*,referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
  "getPointerToAudioLeftBuffer(audiosourceobj*)",referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
  "getPointerToAudioRightBuffer(audiosourceobj*)",referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
  "freeAudioBuffers(audiosourceobj*)",referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
      -[Engine clearAudioInput:pid:] in Engine.o
      -[Engine reset] in Engine.o
  "setAudioInputReadPoint(audiosourceobj*,referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
  "setAudioInputHasAudio(audiosourceobj*,referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
      -[Engine reset] in Engine.o
      -[Engine setAudioPath:channel:pad:] in Engine.o
  "setAudioInputState(audiosourceobj*,referenced from:
      -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o
      -[Engine clearAudioInput:pid:] in Engine.o
      -[Engine reset] in Engine.o
      -[Engine setAudioPath:channel:pad:] in Engine.o
  "initAudioInputHasAudio(audiosourceobj*,signed char)",referenced from:
      -[Engine clearAudioInput:pid:] in Engine.o
      -[Engine reset] in Engine.o
  "initAudioInputReadPoint(audiosourceobj*,referenced from:
      -[Engine clearAudioInput:pid:] in Engine.o
      -[Engine reset] in Engine.o
  "initAudioInputFrameCount(audiosourceobj*,referenced from:
      -[Engine clearAudioInput:pid:] in Engine.o
      -[Engine reset] in Engine.o
  "initAudioInputSampleToAction(audiosourceobj*,referenced from:
      -[Engine clearAudioInput:pid:] in Engine.o
      -[Engine reset] in Engine.o
  "newChannelOBJ()",referenced from:
      setUpChannels(int,int)in Engine.o
  "setVolume(channelobj*,float)",int)in Engine.o
  "setMute(channelobj*,int)in Engine.o
  "setNumberOfInputs(channelobj*,int)in Engine.o
  "setChannelID(channelobj*,int)in Engine.o
  "createInputs(channelobj*,int)in Engine.o
  "setBufferSize(channelobj*,int)in Engine.o
  "createChannelEQS(channelobj*)",int)in Engine.o
  "actionupdatecomplete(audiosourceobj*,objc_object*)",referenced from:
      channelMixerCallback(void*,unsigned long*,AudioTimeStamp const*,unsigned long,AudioBufferList*)in Engine.o

解决方法

听起来你的函数有C链接,但你没有在它们的标题中正确声明.因此.mm文件(Objective-C)将会看到它们并假设C链接.最简单的解决方法是将#include语句包装在适当的extern块中:
extern "C" {
    #include "..."
}

更好的解决方案是在标头本身内执行此操作:

#if defined(__cplusplus)
    extern "C" {
#endif /* defined(__cplusplus) */

extern void whatever(void);
extern int foobar(double);
...

#if defined(__cplusplus)
    }
#endif /* defined(__cplusplus) */

Apple为此使用宏,名为__BEGIN_DECLS和__END_DECLS,但它们是非标准的,因此您无法直接在跨平台共享的文件中使用它们.

猜你在找的C&C++相关文章