0

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

I'm trying to plot some matrices on 3D-graphs using MathGL with XCode. I managed (after a long day of frustration) to cmake, make and install MathGL (even had to install libpng, but that's a differents story). So, I managed to add the MathGL include path (/usr/local/include) to the XCode C++ project and it is working, since the autocompletion autocompletes the mgl2/mgl.h header file. Yet when I'm trying to build my code, which is only making one mglGraph member, I'm getting many linker errors:

Undefined symbols for architecture i386:
  "_mgl_create_graph", referenced from:
      _main in main.o
  "_mgl_delete_graph", referenced from:
      mglGraph::~mglGraph() in main.o
  "_mgl_set_font_size", referenced from:
      mglGraph::SetFontSizePT(double, int) in main.o
  "_mgl_use_graph", referenced from:
      mglGraph::~mglGraph() in main.o
ld: symbol(s) not found for architecture i386

I know there are many posts out there (some even from me) listing problems with including correctly etc. but this one I just can't find any help for. So please anybody, how do I get this to work?

I've tried changing/modifying the environment PATH and DYLD_* paths to include the /usr/local/... paths, but that didn't work. I've tried adding ALL folders in /usr/local/ to the include path. I've tried compiling in 32 and 64 bit. I've tried including the /usr/local/lib in the library search path. But nothing worked. So please any help is very much appreciated.

Regards Max

Community
  • 1
  • 1
Max Z.
  • 801
  • 1
  • 9
  • 25
  • http://stackoverflow.com/a/12574400/673730 – Luchian Grigore Nov 05 '12 at 12:30
  • 1
    The problem isn't including files, but with linking. – Luchian Grigore Nov 05 '12 at 12:30
  • I figured that... The solution listed is specific MSVS. But I'm using XCode. On the other hand, I tried compiling with g++ in the terminal and added the linker flag (*-l/usr/local/lib*) but that didn't work either :/ – Max Z. Nov 05 '12 at 13:01
  • You need to specify which exact library to link against. I don't know the command in XCode, but you can easily find it with google. It might be something like `-l/.../mathgl.lib`... – Luchian Grigore Nov 05 '12 at 13:06
  • Hey, thanks for that :D Didn't try "dragging and dropping" the "dylib" file into the project folder. Is seems one has to: 1. Add the *User Header Search Paths*, 2. add the *Library Search Path* and 3. then *drag and drop* the actual library reference into the project folder. Now it compiles, runs and makes my graph(s) :] – Max Z. Nov 05 '12 at 13:22
  • Regardless of the IDE, it's almost always the same - you have to specify which library to use. – Luchian Grigore Nov 05 '12 at 13:31
  • I added the steps to the answer in the related question and voted to close this. Hope you don't mind. – Luchian Grigore Nov 05 '12 at 13:33
  • Since I got my answer, closing this is probably best ;) Ta – Max Z. Nov 05 '12 at 13:37
  • Hi Max, I'm going through the exact same pain of installing Mathgl on mac and your Q popped up. How did you install libpng, as it is causing me a lot of stress! Cheers Sam – Sam Palmer Apr 13 '13 at 20:53
  • I've installed Mathgl, but how did you get xcode to find mgl2/mgl.h ? – Sam Palmer Apr 13 '13 at 21:31
  • @SamPalmer: It's been a while, but I believe I installed libpng like so: First I downloaded it from [here]( http://libpng.sourceforge.net/index.html), then using cmake to make the code, and then `sudo make` & `sudo make install` to install it. It should all automatically install correctly and then just work with MathGL. – Max Z. Apr 14 '13 at 12:57
  • @SamPalmer: Imported (drag-and-drop also works) the libmgl.dlyb into the Project navigator. Then added `/usr/local/include` and `/usr/local/lib` to the **target's** Header Search Paths and Library Search Paths respectively. You know it has worked when trying to write `#include ` in your header and the Xcode autocomplete feature shows the mgl2 folder's content as you do so. – Max Z. Apr 14 '13 at 13:01
  • Cheers, great help its auto-completeing so I guess thats a good sign. – Sam Palmer Apr 14 '13 at 15:25
  • So i've got all the compilation working, did you come across an error that creating the data throws a bad access? – Sam Palmer Apr 14 '13 at 17:00

0 Answers0