unrecognized command line option ‘-framework’ - c

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?

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.

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.

Related

ssize_t undefined in a dpdk header

I have an installation of DPDK and I'm trying to compile code with it. This worked on my WSL machine, however on the test server, with the same install of dpdk, I'm getting the error:
/usr/local/include/rte_mempool.h: error: unknown type name 'ssize_t'
I've noticed this header does not include /sys/types.h, but it also doesn't include that on the machine that this works on. I don't know where it's supposed to come from, but it's coming from somewhere.
How do I get these headers to be aware of ssize_t?
As noted in a comment:
The compiler options include -std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h, and a whole bunch of -l options (dpdk's make structure adds these in). This prompted me to run gcc --version and the working one is Ubuntu gcc 9.3.0 and the broken one is gcc 5.4.0. Seems like it might be an incompatibility between dpdk and the gcc installed.
As mentioned in the comments by #JonathanLeffier, the root cause of the issue is including sys/types.h when gcc option --std=c99 is passed. The easiest fix without modifying the DPDK or sample code is to include the path to types.h as part of cflags.
If the native build is for x86_64 target, follow these steps:
execute find /usr/include/ -name types.h to identify the right file for local build (this is because the current cflags has -march=native)
modify the CFLAGS from -std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h to -std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h --include=/usr/include/[target-machine]/sys/types.h
Note: In my humble suggestion please use pkg-config for populating the right CFLAGS and LDFLAGS for both shared and static binary.

Error building program using gcc plugin from linux kernel source tree

I am trying to use a grsecurity gcc plugin that I found on their unofficial linux kernel source tree (the respectre_plugin/ one).
My GCC version is 4.7, I modified scripts/gcc-plugins/Makefile to make it compile the plugin, and I built it with the root Makefile using make gcc-plugins, that shows no error.
Then, when I try to compile a C file that has a Spectre-like flaw, I got the following build error:
file.c:36:31: error: array_index_mask_nospec is not defined
This function is defined in respectre_plugin/respectre_plugin.c, and I have no idea why I've got this strange build error, if anyone knows about it...
My build invocation is the following:
gcc -Wall -Wextra -std=c99 -fplugin=/path/to/respectre_plugin.so -c file.c -o file.o
Thanks for any help !

Code of Computer Graphics not compiled or installation failed

I followed instruction described http://www.cse.iitm.ac.in/~vplab/courses/CG/opengl_start.html that is as following -
OpenGL (GLUT) on Linux (Ubuntu) Installation
Install the following packages from the ubuntu repository:
1. freeglut3-dev
2. mesa-common-dev
sudo apt-get install freeglut3 freeglut3-dev mesa-common-dev
Check your /usr/include/GL folder to verify the installation of the openGL headers that you intend to use.
Compiling and Linking
You will have to use the -lglut linker option with gcc/g++ to compile a program with glut library.
For example, to compile the program cube.c that uses GLUT type, use
gcc -o cube cube.c -lglut -lGLU
to get the binary executable cube.
If you are not using GLUT and want to use the lower level libraries then use -lGL -lGLU also in the linker options.
But, this doesn't work for me.
$gcc -o cube cube.c -lglut -lGLU
/usr/bin/ld: /tmp/cc5OzQPt.o: undefined reference to symbol 'glVertex3fv'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
And I didn't get the solution. Help me.
I want to write code in C and my environment is Ubuntu 14.04, Intel processor.
Try this -
gcc -o cube cube.c -lglut -lGLU -lGL

Why gcc doesn't recognize -rdynamic option?

I got a gcc compilation error:
gcc-4.9: error: unrecognized command line option '-rdynamic'
and I tested compilation with -rdynamic in some environments. While I used the same version of gcc (4.9.2), in some environments gcc worked well, but others (e.g. Homebrew gcc 4.9.2_1, cygwin 64bit) not. What makes the difference?
-rdynamic passes the flag -export-dynamic to ELF linker, on targets that support it.
Executable formats in OS X and Windows are not ELF, thus the option -rdynamic is not supported building for these operating systems.

gcc /usr/bin/ld: error: cannot find -lncurses

I am running Ubuntu 12.04 and I'm currently working on a project involving C, OpenGL, a teapot and input methods.
The problem started when I decided to have arrow keys as input. I checked to see the key codes for arrow keys but all of the arrows return 0. I looked up how to get this to work and I found conio.h. Unfortunately, it is an old DOS header that is not available for Linux. Then I found a substitute called ncurses.
After installing the necessary libraries, by following the build instructions closely, I #included curses.h in my main.c source. When I first tried to compile using gcc, I got the following errors:
main.o:main.c:function _Key: error: undefined reference to 'stdscr'
main.o:main.c:function _Key: error: undefined reference to 'wgetch'
main.o:main.c:function _Key: error: undefined reference to 'stdscr'
main.o:main.c:function _Key: error: undefined reference to 'wgetch'
I found a fix by adding -lncurses to the makefile like so:
SOURCES=main.c
main: main.o
gcc -lm -lGL -lGLU -lglut -lncurses main.o -o main
main.o: main.c
gcc -lm -lGL -lGLU -lglut -c main.c
But I was greeted by another error:
/usr/bin/ld: error: cannot find -lncurses
As well as the previous errors.
I have spent the last 2 days searching both the Ubuntu forums and StackOverFlow. Any help would be appreciated.
P.S. I don't know if this is important but when I try to run /usr/bin/ld I get this error:
ld: fatal error: no input files
For anyone with the same problem I had: I was missing the 32 bit libraries; I was compiling 32 bit on a 64 bit server which was missing the lib32ncurses5-dev package.
On Ubuntu I simply ran:
sudo apt-get install lib32ncurses5-dev
First off, you should put the libraries after the object file when linking. And not have them at all in the compilation of of the source file.
After that, if ncurses is not installed in a standard search folder you need to point out to the linker where it is, this is done with the -L command line option:
gcc main.o -o main -L/location/of/ncurses -lm -lGL -lGLU -lglut -lncurses
Try installing the ncurses-static package too, if you have only the ncurses-devel package installed in your Ubuntu OS.
If that solves your problem, plus if you add #Joachim's compiling instructions, you are off to a great start.
gcc main.o -o main -L/location/of/ncurses -lm -lGL -lGLU -lglut -lncurses
The linker can't find your shared library in it's search path. If you add the directory where your shared lib is to the LD_LIBRARY_PATH environment variable the linker should find it and be able to link against it. In that case you could omit the -L option to gcc:
gcc main.o -o main -lm -lGL -lGLU -lglut -lncurses
And it should compile fine.
EDIT:
Good to know that apt-get install libncurses5-dev fixes your problem.
FYI.
The LD_LIBRARY_PATH environment variable contains a colon separated list of paths that the linker uses to resolve library dependencies at run time. These paths will be given priority over the standard library paths /lib and /usr/lib. The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has been exhausted.
The best way to use LD_LIBRARY_PATH is to set it on the command line or script immediately before executing the program. This way you can keep the new LD_LIBRARY_PATH isolated from the rest of your system i.e. local to the current running running instance of shell.
$ export LD_LIBRARY_PATH="/path/to/libncurses/library/directory/:$LD_LIBRARY_PATH"
$ gcc main.o -o main -lm -lGL -lGLU -lglut -lncurses

Resources