2

I am starting to use the igl library for 3d in C++, on my mac. As I followed the tutorial, an error appeared. The first exemple, basically just reading an OFF file, works fine. But the second one, using igl::viewer doesn't. Here is the code :

#include <igl/readOFF.h>
#include <igl/viewer/Viewer.h>

Eigen::MatrixXd V;
Eigen::MatrixXi F;

int main(int argc, char *argv[])
{
    // Load a mesh in OFF format
    igl::readOFF("/bunny.off", V, F);

    // Plot the mesh
    igl::viewer::Viewer viewer;
    viewer.data.set_mesh(V, F);
    viewer.launch();
}

and I just enter in the terminal :

g++ -std=c++11 -I path_to_librairies/eigen-eigen-07105f7124f9/ -I path_to_librairies/libigl/include/ -I path_to_libraries/glfw-3.1.2/include/ main.cpp -o Test

where path_to_libraries is a personal folder in which my libraries (igl, eigen, glfw) remain.

And the terminal returns dozens of errors like :

Undefined symbols for architecture x86_64:
  "_glActiveTexture", referenced from:
      igl::viewer::OpenGL_state::bind_mesh() in main-805320.o

I also downloaded Eigen and glfw. All I did is a cmake in the glfw source folder.

Finalement, I should add that when I tried with Xcode, adding in the project the framework OpenGL (something I found on the internet) removed half of the errors (the one concerning igl::viewer::OpenGL) but some igl::viewer::Viewer ones remain.

Does anyone have any clue?

Alec Jacobson
  • 6,032
  • 5
  • 51
  • 88
  • You are not linking with an OpenGL library? I don´t know how this is done on OSX (more of linux/windows kinda guy) but that is where I would start. Good luck – Andreas Apr 05 '16 at 16:58

1 Answers1

5

You most likely need to link in a few of OS X's frameworks, according to GLFW's docs, adding

-lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo

should fix your problem.

Leandros
  • 16,805
  • 9
  • 69
  • 108
  • Thanks it helped ! I had 76 errors of that type, now 26. The remaining ones concern igl::viewer::Viewer::launch_something() like for instance : Undefined symbols for architecture x86_64: "_glfwCreateWindow", referenced from: igl::viewer::Viewer::launch_init(bool, bool) in main.o – Martin Jocqueviel Apr 05 '16 at 17:26
  • Now you're not linking the GLFW library itself. Look at the docs I linked, and add the flag `-lglfw` to link GLFW. And you would also have to add a `-L` flag, to tell the compiler where to look for the library. – Leandros Apr 05 '16 at 18:23
  • Ok great it finally works ! (I also had to install glfw after the make, which I did not do first). Thank you very much. – Martin Jocqueviel Apr 06 '16 at 09:19