PintoDoido
PintoDoido

Reputation: 1051

unrecognized command line option ‘-framework’

I am trying to compile the minimalist C opengl code in https://github.com/fogleman/HelloGL on my Ubuntu 18.04 system, but I get the following error:

gcc -c -o build/matrix.o -std=c99 -O3 src/matrix.c    
gcc -o main build/shader.o build/main.o build/util.o build/matrix.o  -lglew -lglfw3 -framework Cocoa 
-framework OpenGL -framework IOKit -framework CoreVideo -lm    
gcc: error: Cocoa: No such file or directory    
gcc: error: OpenGL: No such file or directory    
gcc: error: IOKit: No such file or directory    
gcc: error: CoreVideo: No such file or directory    
gcc: error: unrecognized command line option ‘-framework’    
gcc: error: unrecognized command line option ‘-framework’    
gcc: error: unrecognized command line option ‘-framework’   
gcc: error: unrecognized command line option ‘-framework’    
Makefile:24: recipe for target 'main' failed

I do realize the reason for this is the following line in the MakeFIle, which is made for OSX (presumably):

LIBS = -lglew -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo

Is there a way of adapting this line to make it work on a GNU/Linux system? Or does it need to have to be linked to the Cocoa framework?

Upvotes: 2

Views: 6679

Answers (2)

zwol
zwol

Reputation: 140786

I downloaded this example project and tinkered with it myself. It does not appear to contain any OSX-specific code; it's just that its Makefile was written for OSX only.

First make sure you have have the libglfw3-dev and libglew-dev packages installed. Installing these from the Ubuntu package manager should automatically pull in all the other libraries that are required.

Next, change the LIBS line of the Makefile to read

LIBS = -lGLEW -lglfw -lGL -lm

For no apparent reason, the library called libglew on OSX is called libGLEW on (Debian-style) Linux, and the library called libglfw3 on OSX is called libglfw on Linux. -lGL is the Linux equivalent of -framework OpenGL, and -lm brings in the math library (needed for one call to sqrt), which is separate from the core C library on Linux but not on OSX, if I remember correctly.

You may also need to adjust the FLAGS line. This setting worked for me:

FLAGS = -g -O2 -std=gnu99 -Wall -Wextra -Wpedantic

The important change here is -std=gnu99 instead of -std=c99. The stricter c99 mode is troublesome; it disables extensions that people don't realize are extensions, like math.h defining the constant M_PI, which this program wants. (It also has a nasty habit of breaking network-related system headers, for reasons which are too complicated to get into here. Fortunately, this program doesn't use the network.)

I also added -Wall -Wextra -Wpedantic, added -g, and changed -O3 to -O2. These are all things I do habitually to every C program I tinker with. The first two can reveal problems and they almost never hurt; in this case they didn't make any visible difference. The third is because -O3 often makes your program slower than -O2 would have.

Upvotes: 5

Clifford
Clifford

Reputation: 93556

The -framework option is specific to Apple platforms, as the Cocoa, IOKit and CoreVideo frameworks themselves. The build commands and options you are using are for macOS it would appear.

Upvotes: 1

Related Questions