我最近将一个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*, 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
答案 0 :(得分: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) */
Apple为此使用宏,名称很好__BEGIN_DECLS
和__END_DECLS
,但它们是非标准的,因此您无法直接在跨平台共享的文件中使用它们。