Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.mm conversion causes Undefined symbols for architecture i386 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 20 or so errors. What exactly do these errors mean and how can I change MyClass to an objective c++ class to facilitate the new c++ class 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
like image 871
dubbeat Avatar asked Sep 12 '11 16:09

dubbeat


1 Answers

Sounds like your functions have C linkage, but you haven't declared that properly in their header. So a .mm file (Objective-C++) is going to see them and assume C++ linkage. The easiest fix is to wrap that #include statement in the appropriate extern block:

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

A better solution is to do that within 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, nicely named __BEGIN_DECLS and __END_DECLS but they're nonstandard so you can't use them directly in files that are shared across platforms.

like image 148
Jonathan Grynspan Avatar answered Nov 14 '22 20:11

Jonathan Grynspan