Glib C : program does not recognize GLIB library - c

I have a problem with my C program, when I want to compile it. It works on Ubuntu 11.04, but when I move to Ubuntu 13 I get this problem.
I compile with this Makefile:
all:
gcc -D_GNU_SOURCE -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include \
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -lglib-2.0 -D_FILE_OFFSET_BITS=64 \
-D_LARGEFILE_SOURCE -g -Wall -Wextra -std=c99 -lm *.c -o concatener
I get these errors:
undefined reference to « g_str_equal »
undefined reference to « g_str_equal »
undefined reference to « g_array_remove_index »
undefined reference to « g_array_remove_index »
Why does it not recognize these functions? Have I linked to the glib library wrong?

The gcc command looks fine, I cannot see anything obviously wrong, linking with -lglib-2.0 should be what you want1.
What I am guessing is the case is that on your Ubuntu 11.04 system you have the glib development package installed while it is not installed on your 13 system. I think the package name should be libglib2.0-dev.
1
If you want to be a bit more generic you can replace the hardcoded compile and link options with
`pkg-config --cflags glib-2.0`
and
`pkg-config --libs glib-2.0`

Related

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
...

Why does tcc not recognize "main" when I include the -pthreads flag?

I am trying to compile a c application with the gtk 3.0 library with tcc. The documentation says the command to run to compile is
gcc `pkg-config --cflags gtk+-3.0` -o [executable name] [source file] `pkg-config --libs gtk+-3.0`
I am trying to use tcc to compile, and it from what I can tell, the syntax should be the same. However, where gcc compiles it fine, when I use tcc, compilation fails with the error:
tcc: error: undefined symbol 'main'
I isolated the problem to the -pthread flag inserted by pkg-config --cflags gtk+-3.0 Thus, running a simple "Hello, World" c program and compiling with
tcc -pthread -o [executable name] [source file]
results in the same error. Am I compiling wrong, is it a compiler bug, or something else?
try -lpthread
tcc hello.c -lpthread -o hello

gcc cannot find -lglfw3

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

Compiling a C program that uses OpenGl in Mac OS X

I am trying to compile a C program for my CS class. I have Command Line tools installed on my Mac, so I probably have OpenGL. The program description was made for Ubuntu and it says for me to compile using:
gcc -Wall -ansi -pedantic -O2 main.o graphic.o imagem.o io.o -o ep2 -lGL -lGLU -lglut
I ran that and it said:
ld: library not found for -lGL
What flags should I use? What do I do?
In MacOS X you're not using libraries to include system level APIs, but Frameworks. The proper command line to compile this program would be
gcc -Wall -ansi -pedantic -O2 \
main.o graphic.o imagem.o io.o \
-o ep2 \
-framework OpenGL -lGLU -lglut
Note that GLU is probably part of the OpenGL framework as well. And it may be required to install GLUT first.
I found you have to use
-framework OpenGL -framework GLUT
Reference

Resources