2011-09-12 52 views
6

我最近将一个C++文件导入到我想要使用的obj项目中。在我想使用它的课程中,我将文件名从MyClass.m更改为MyClass.mm。.mm转换导致架构i386错误的未定义符号

这样做会给我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*, int)", 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*, int)", referenced from: 
     -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o 
    "setAudioInputHasAudio(audiosourceobj*, bool)", referenced from: 
     -[Engine extractMp3Audio:withChannelId:withPadId:] in Engine.o 
     -[Engine reset] in Engine.o 
     -[Engine setAudioPath:channel:pad:] in Engine.o 
    "setAudioInputState(audiosourceobj*, int)", 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*, int)", referenced from: 
     -[Engine clearAudioInput:pid:] in Engine.o 
     -[Engine reset] in Engine.o 
    "initAudioInputFrameCount(audiosourceobj*, int)", referenced from: 
     -[Engine clearAudioInput:pid:] in Engine.o 
     -[Engine reset] in Engine.o 
    "initAudioInputSampleToAction(audiosourceobj*, int)", 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)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "setMute(channelobj*, int)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "setNumberOfInputs(channelobj*, int)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "setChannelID(channelobj*, int)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "createInputs(channelobj*, int)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "setBufferSize(channelobj*, float)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "createChannelEQS(channelobj*)", referenced from: 
     setUpChannels(int, int)in Engine.o 
    "actionupdatecomplete(audiosourceobj*, objc_object*)", referenced from: 
     channelMixerCallback(void*, unsigned long*, AudioTimeStamp const*, unsigned long, unsigned long, AudioBufferList*)in Engine.o 

回答

19

听起来像你的函数有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) */ 

苹果使用宏这个,很好地命名为__BEGIN_DECLS__END_DECLS,但它们是非标准的,因此您不能直接在跨平台共享的文件中使用它们。

+0

谢谢。你在这个答案中发布的一切对我来说都是全新的 – dubbeat

+0

在开始使用它之前,你应该阅读C++。像这样的事情如果你弄错了,以后可能会再次咬你。 –

相关问题