glew architecture x86_64 error

Hi,
I used glut and sdl2 before and now i tried to make something completely on my own with openGL, sdl2 and glew. I wrote my own makefile now and i think it works, but i always get this error when i try to compile it:


g++ -c -Wall -I/usr/local/include main.cpp
g++ -c -Wall -I/usr/local/include Display.cpp 
g++ -L/usr/local/lib -lSDL2 -lGLEW  -o booom main.o Display.o
Undefined symbols for architecture x86_64:
  "_glClear", referenced from:
      Display::Clear(float, float, float, float) in Display.o
  "_glClearColor", referenced from:
      Display::Clear(float, float, float, float) in Display.o
  "_glCullFace", referenced from:
      Display::Display(int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Display.o
  "_glEnable", referenced from:
      Display::Display(int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Display.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

I have only my main.cpp and my Display class. This small program should only create a window for me.

I try to compile it on osx, version 10.9.5.
glew version: 1.12.0 (compiled on my own, also tried it with the homebrew version. changes nothing)
sdl2 version: 2.0.3

Here is my makefile:


#my compiler
CC=g++

#my program name
PRGNAME=booom

#library search directory
LIBDIR=-L/usr/local/lib

#library names
#uses libSDL2.a, libGLEW.a
LIBNAME=-lSDL2 -lGLEW 

#includes for libraries
INCLUDES=-I/usr/local/include

#my compiler options
CFLAGS=-c -Wall


all: main.o Display.o
	$(CC) $(LIBDIR) $(LIBNAME) -o $(PRGNAME) main.o Display.o

#main.cpp is the dependency of main.o
main.o: main.cpp
	$(CC) $(CFLAGS) $(INCLUDES) main.cpp

Display.o: Display.cpp
	$(CC) $(CFLAGS) $(INCLUDES) Display.cpp 

clean:
	rm -rf *o booom

i searched a lot on google,but i haven’t found a fix that works for me. also most people on osx use xcode, but i don’t want to use xcode anymore because its osx only.

[QUOTE=mehrschwein;1264877]Hi,
I used glut and sdl2 before and now i tried to make something completely on my own with openGL, sdl2 and glew. I wrote my own makefile now and i think it works, but i always get this error when i try to compile it:


g++ -c -Wall -I/usr/local/include main.cpp
g++ -c -Wall -I/usr/local/include Display.cpp 
g++ -L/usr/local/lib -lSDL2 -lGLEW  -o booom main.o Display.o
Undefined symbols for architecture x86_64:
  "_glClear", referenced from:
      Display::Clear(float, float, float, float) in Display.o
  "_glClearColor", referenced from:
      Display::Clear(float, float, float, float) in Display.o...

[/QUOTE]

Don’t know about OSX, but most (all Linux distros) put 32-bit libs in …/lib and 64-bit libs in …/lib64.

Instead try: -L/usr/local/lib64 (if youre OSX box has your 64-bit libGL.* libs in /usr/local/lib64). Normally the GL libs are placed in a system directory so you don’t even need a -L argument to help the linker find them.

OSX uses fat binaries. All of the GL-related libraries shipped with the system are fat.

Try the “file” command on each of the libs you are linking. Fix your build for whichever one isn’t x86_64 (i.e. add “-arch x86_64”.)

i don’t want to use xcode anymore because its osx only.

Nothing wrong with that. But you might look at an Xcode build log to see all the flags you might need to replicate in your make.

Thank you for your help, but i wasn’t able to solve to problem yet. when compiling glew i get some warnings about deprecated functions. glew uses AGL to compile on OS X and i don’t know if it may have something to do with this (https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/AGL_OpenGL/#//apple_ref/c/func/aglCreatePixelFormat).
It also uses the -arch x86_64 option already.
I also tryed to build it with xcode now to see if i need to change something in my makefile, but i get the same error. Somehow he doesn’t want to give me a good glew version for my architecture.

well, seams like AGL is not supported anymore and is only for 32-bit.

AGL is fat:

$ file /System/Library/Frameworks/AGL.framework/Versions/A/AGL
/System/Library/Frameworks/AGL.framework/Versions/A/AGL: Mach-O universal binary with 2 architectures
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (for architecture x86_64):    Mach-O 64-bit dynamically linked shared library x86_64
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (for architecture i386):    Mach-O dynamically linked shared library i386

…however AGL depends on Carbon for the window interface, which is certainly deprecated.

any idea how i can work around that? i need glew and can’t get it working :frowning:
Im not sure if its even AGL what creates my problem. AGL only gives warnings when compiling glew, but it may not be my problem. anyone out there with OS X 10.10 who made glew work and was able to use it?

Try linking OpenGL:

LIBNAME=-lSDL2 -lGLEW -framework OpenGL

well… yea, it works now… thank you.
wow
i really forgot that

I had the same problem and your solution works great for me!

Thank you so much :slight_smile:

[QUOTE=arekkusu;1265038]Try linking OpenGL:

LIBNAME=-lSDL2 -lGLEW -framework OpenGL

[/QUOTE]