.mm conversion causes Undefined characters for i386 architecture errors

I recently imported a C ++ file into my obj project that I want to use. In the class I want to use it in I change the file name from MyClass.m to MyClass.mm.

Doing this gives me about 20 errors. What exactly do these errors mean and how can I change MyClass to a C ++ object class to facilitate the new C ++ class that I want to use without getting these errors?

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 
+6
source share
1 answer

It looks like your functions have a C link, but you did not declare it correctly in your header. So the .mm file (Objective-C ++) will see them and suggest a C ++ connection. The simplest fix is ​​to wrap this #include statement in the corresponding extern block:

 extern "C" { #include "..." } 

The best solution is to do this inside the header itself:

 #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ extern void whatever(void); extern int foobar(double); ... #if defined(__cplusplus) } #endif /* defined(__cplusplus) */ 

Apple uses macros for this, beautifully named __BEGIN_DECLS and __END_DECLS , but they are non-standard, so you cannot use them directly in files that are available for different platforms.

+19
source

Source: https://habr.com/ru/post/897165/


All Articles