gcc cannot find -lglfw3 - c

I'm on a linux system (arch linux specifically) and I'm trying to compile the introduction project from the official glfw page but I cannot seem to get gcc to compile it. If anyone doesn't know what I'm talking about it's this.
Also this is how I'm trying to compile it:
gcc -Iinclude test.c -o test -lglfw3 -lm -lGL -lGLU
and it gives me the following errors:
/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status

I completely forgot about this question until I got a notification for it. For me the solution was to not use -lglfw3 but rather use -lglfw

If you've installed pkg-config, and glfw3.pc is in the search path, try:
gcc -Iinclude test.c -o test `pkg-config --libs glfw3` -lm -lGL -lGLU
If you only have the static build, use: pkg-config --static --libs glfw3, which will add the dependencies that libglfw3.a requires.

Find libglfw3.a or libglfw3.so on your system
Mention that path to gcc using -L
gcc -Iinclude test.c -o test -L/dir/where/glfw3/resides -lglfw3 -lm -lGL -lGLU

Related

C how do i import/link glfw with gcc on linux

this shit doesn't work. why?
gcc -c -Wall src/*.c -g -m64 && gcc -Iinclude *.o -o bin/debug/main -Lusr/local/lib -l libglfw && ./bin/debug/main
i get this linking error when trying to build the glfw window example
/usr/bin/ld: cannot find -l libglfw
collect2: error: ld returned 1 exit status
How do i import/link glfw and what is going wrong? I tried dynamically linking from usr/lib/x86_64-linux-gnu/libglfw.so but it didn't help. I'm pretty new to gcc and linux so i could just be stupid.
EDIT:
the comments pointed out a few mistakes i made so here's the new command, which is wrong too for some reason:
gcc -c -Wall src/*.c -g -m64 && gcc -Iinclude *.o -o bin/debug/main -L/usr/local/lib -lglfw && ./bin/debug/main
the new error:
/usr/bin/ld: main.o: in function `main':
/home/basti/dev/OpenGL/src/main.c:26: undefined reference to `glClear'
collect2: error: ld returned 1 exit status
I figured it out. Thanks to comments i managed to fix linking and didn't realize i had to import other opengl stuff.
In case somone is searching for an answer to the same problem here's my debug build command for sublime text 3:
gcc -c -Wall src/*.c -g -m64 && gcc -Iinclude *.o -o bin/debug/main -lglfw -lGLU -lGL && ./bin/debug/main

SDL 2 C Compiler Flags

Whenever I run the following, I get undefined references to all the SDL-related functions used in my program:
cc -lSDL2 -lGL *.o
I believe this is caused by the lack of -l linker flags.
GCC arguments are positional, put the link flags after your o files:
gcc *.o -lSDL2 -lGL
Also, if you're on a proper full Linux system I'd recommend using pkg-config to pull compiler/linker flags:
gcc -c main.c `pkg-config sdl2 --cflags`
gcc main.o `pkg-config sdl2 --libs`

installed check for c but "check.h" not found

Im using windows 10 with wsl ubuntu 18.04 Im trying to run the code from here :
https://www.ccs.neu.edu/home/skotthe/classes/cs5600/fall/2015/labs/intro-check-lab-code.tgz
I installed gcc, makefile, and check in the ubuntu terminal. But when I di $ make it says:
gcc money.o check_money.o -lcheck -lm -lpthread -lrt -lgcov -coverage -o check_money_tests
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check_log.o): In function `subunit_lfun':
(.text+0x5f4): undefined reference to `subunit_test_start'
(.text+0x6bf): undefined reference to `subunit_test_fail'
(.text+0x6d4): undefined reference to `subunit_test_pass'
(.text+0x6ef): undefined reference to `subunit_test_error'
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'check_money_tests' failed
make: *** [check_money_tests] Error 1
so I open the check_money.c it says that check.h cannot be found. What did I miss here?
Simple version: you should also link with -lsubunit flag, i.e.:
TST_LIBS = -lcheck -lm -lpthread -lrt -lsubunit
Better yet, all the flags should be taken from check's package configuration, as the requirements depend on how the check library was built (and that's what pkg-config has been invented for). So instead of hardcoding your options, you could improve your Makefile like this:
CFLAGS = -c -Wall $(shell pkg-config --cflags check)
TST_LIBS = $(shell pkg-config --libs check)
Result:
$ make
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage src/*.c
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage tests/*.c
gcc money.o check_money.o -lcheck_pic -pthread -lrt -lm -lsubunit -lgcov -coverage -o check_money_tests
...

using C and cuda create shared library got error at link stage

I was really struggled with this error when I try to build a shared library. My code utilize the Lapacke library and also CUDA. when I compile them, there are no errors(I compile them as)
gcc -m64 -Wall -fPIC -c xxx.c -o xxx.o $(INC)
where INC includes all directories
INC=-I. -I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux/ I$/home/sniu/lapack-3.5.0/lapacke/include/ -I${CUDA_INSTALL_PATH}/include/ -I/home/sniu/CBLAS/include/
for cuda part, I wrote it as:
nvcc -m64 -arch=sm_20 -Xcompiler -fPIC $(INC) -c xxx.cu -o xxx.o
but I got the error message at the link stage:
gcc -m64 -D_REENTRANT -Wall -fPIC -g -shared -o libjniWrapper.so jniWrapper.o cholesky_inv.o wls_acc.o utils.o -L/home/sniu/lapack-3.5.0 -L/opt/cuda-toolkit/5.5.22/lib64 -lm -llapacke -llapack -lblas -lgfortran -lrt -lcudart -lcublas -ldl
/usr/bin/ld: /home/sniu/lapack-3.5.0/liblapacke.a(lapacke_dpotrf.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/sniu/lapack-3.5.0/liblapacke.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
I am very sure libraries are there, I really confused why I got this error.
Any suggestions are appreciated, Thank you so much!

gcc Link Order issue

I am currently having problems compiling with the following line:
gcc test.c -I/usr/include -L/lib -lipc -lpcd -lrt -o /home/examples/bin/test
I was suggested to group them using start-group and end-group.
I am not able to get the proper syntax.
I think i need this part, but what do the whole line look like?
-Wl,--start-group -lipc -lpcd -lrt -Wl,--end-group
Which problem are you having ?
Anyway, try putting the linker arguments at the end:
gcc test.c -o /home/examples/bin/test -I/usr/include -L/lib -lipc -lpcd -lrt

Resources