I have a simple program
#include
int main(){
g_print(\"hallo\\n\");
}
and try to compile it on the embedded system (Odroid
Ok found a solution
gcc -o main main.c `pkg-config --libs --cflags glib-2.0`
works, but I don't know why on my X64 linux system it worked also the other way.
You need to add the $(pgk-config --libs glib-2.0)
after the main.c
in your compile line - because library functions are only dragged into the binary if there is anything using them - so main.c is what is using the g_print
, and if the -lglib
(or whatever the result of the pkg-config
bit is) is before main.c
, it doesn't get included in the resulting binary.
The order of options to gcc
(and other compilers) matters.
gcc -Wall main.c $(pkg-config --libs --cflags glib-2.0) -o main
And I don't really like the above. You should learn how to use GNU make. At the very least, put the compile flags, then the sources, then the object files, then the libraries (from high level to low level).
gcc -Wall $(pkg-config --cflags glib-2.0) main.c \
$(pkg-config --libs glib-2.0) -o main
Better yet, have a Makefile
starting with
CC=gcc
CFLAGS= -Wall $(pkg-config --cflags glib-2.0)
LIBES= $(pkg-config --libs glib-2.0)
And compiling as root should be avoided. Only installation should require root privilege...
You probably want to add -g
(compiler flag for debugging information). Once the program is ready and nearly bugfree, replace it with -O2
(optimizations) and do some serious testing again!