iPlug2 Forum

Linker errors (e.g. Undefined symbol)

/** located in a new text control class IChordTextControl in IControl.h, that inherits from ITextControl in IControl.h */

void updateChordText() { ChordAnalyser ca = ChordAnalyser(notes);} // [1] ChordAnalyser.h is found in iplug2root/Examples/IPlugInstrument(didn't bother using duplicate.py)/ChordAnalyser/ChordAnalyser.h

First of all, I recognise this is more of a general programming question, but I thought it might be useful to ask it here in case someone else runs into a similar problem. But anyways sorry in advance if this doesn’t belong here lol.

I can right click ChordAnalyser at [1], and click jump to definition and xcode will indeed jump to the file in root/examples/myproject/chordanalyser/, but when I build the project (cmd+b), I get this kind of error.

Undefined symbol: ChordAnalyser::ChordAnalyser(std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> >)

I think the issue is that the unmodified example xcode project build settings aren’t recognising ChordAnalyser.h if that makes sense, and if it is, I would like some guidance on how to modify the xcode project so that it also “recognises” ChordAnalyser.h. Another solution I thought of was if I needed to also include a ChordAnalyser.cpp? But I tried this without modifying the example xcode project’s build settings with no luck (I still get the undefined symbol error). And I also just tried straight up putting ChordAnalyser.h in the same folder as IControl.h, but that also didn’t seem to work. Thanks in advance.

Ok, so I realised that the issue was that ChordAnalyser::ChordAnalyser() was declared, but not defined/implemented (this is something I should have realised if I had looked at the stackoverflow threads regarding the error more carefully my bad), so I replaced the ChordAnalyser(std::set notes); line (the declaration of the constructor) in ChordAnalyser.h with ChordAnalyser(std::set notes) {} (the declaration and definition, I think i’m using these terms wrong but hopefully it makes sense) and now it’s building fine. Oh, and one more thing I did was move chordanalyser.h to the same folder as IControl.h, also probably not ideal.

This is a good enough solution for my problem/project, but I’m interested to know how to implement(?) the (at least for me) more ideal solution of having the implementation/definition be in a seperate source code file ChordAnalyser.cpp (with a #include “ChordAnalyser.h” at the top). I tried doing this and for some reason ChordAnalyser.cpp can’t find the header file (even though they are both in the same folder), which I assume is an issue with the xcode build settings. And also what to do to the build settings if I want to put these files in a different folder like root/examples/myproject/chordanalyser/.

l usually add my code files to the project folder, it seems to be the only place where they are recognised by Xcode

Yeah I put them in the main project folder (not 'projects) and drag them into the mac OS bit of the project files list of XCode. When I first moved to IPlug2 I couldn’t get past this error until I realised I’d put them in the iOS bit instead! Probably not the problem here but adding in case anyone else hits the same hurdle.