0

So I am learning OpenGL 4 from openglbook.

I copied and pasted the simple window creating program in my editor and followed Compiling OpenGL programs on OS X by using

gcc -o hello hello.c -framework OpenGL -framework GLUT

I got the following error:

Undefined symbols for architecture x86_64: "_glewGetErrorString", referenced from: _Initialize in chapter-c8ba2d.o "_glewInit", referenced from: _Initialize in chapter-c8ba2d.o "_glutInitContextFlags", referenced from: _InitWindow in chapter-c8ba2d.o "_glutInitContextProfile", referenced from: _InitWindow in chapter-c8ba2d.o "_glutInitContextVersion", referenced from: _InitWindow in chapter-c8ba2d.o "_glutSetOption", referenced from: _InitWindow in chapter-c8ba2d.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

gjjhhh_
  • 169
  • 3
  • 21
  • Looks like the GLUT isn't found or isn't built for x86_64. This page may help: http://web.eecs.umich.edu/~sugih/courses/eecs487/glut-howto/#mac – L. Scott Johnson May 23 '17 at 17:52
  • Before I learn OpenGL 4 with c, I was using OpenGL with c++. It worked totally fine when I compile my program with `g++ -o out out.cpp -framework OpenGL -framework GLUT`. Does this mean my GLUT is built it is just not found? Thanks – gjjhhh_ May 23 '17 at 18:30
  • The only symbols it's not finding are from glut and glew. I assume you have other gl calls in there somewhere which means it's linking to the OpenGL framework just fine. – L. Scott Johnson May 23 '17 at 18:33
  • GLEW is separate from GLUT and OpenGL. Isn't it? – Yunnosch May 23 '17 at 20:59

1 Answers1

0

If I understand correctly, the problem is tha -framework GLUT means that you're linking against the GLUT framework shipped by Apple with macOS and located inside /System/Library/Frameworks folder. This GLUT implementation unfortunately lacks some functionality provided by current version of FreeGLUT. And OpenGLBook.com tutorials use some of this functionality, thus, as it is mentioned many times here, the code examples have to be compiled with FreeGLUT.

There are, of course, few ways this can be done. The easiest one is by installing freeglut by means of the infamous Homebrew package manager and then setting up the CMake project as described below.

So, first install freeglut

brew install freeglut

Then setup CMake project by adding the following lines into CMakeLists.txt

find_package(FreeGLUT CONFIG REQUIRED)
find_package(glew CONFIG REQUIRED)

link_libraries(FreeGLUT::freeglut GLEW::GLEW)
Wildcat
  • 8,701
  • 6
  • 42
  • 63