2011-09-12 75 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++。像這樣的事情如果你弄錯了,以後可能會再次咬你。 –

相關問題