0

I am not sure if this is the correct way of asking my question.. I just tried to solve the problem for 4 days, and I am extremely frustrated right now... I have the following issue:

I installed Ubuntu 13. and some libraries and packages afterwards. I then installed glib2 Everything went fine, I got no errors when doing ./configure, make, or make install. However, when I try to compile a test file in C, I can compile without errors, but I get the following errors:

main.c:116: référence indéfinie vers « g_hash_table_new_full »

main.c:139: référence indéfinie vers « g_hash_table_lookup »

main.c:168: référence indéfinie vers « g_hash_table_insert »

main.c:181: référence indéfinie vers « g_hash_table_lookup »

main.c:211: référence indéfinie vers « g_hash_table_insert »

main.c:250: référence indéfinie vers « g_hash_table_lookup »

I compile with:

gcc -D_GNU_SOURCE -I/usr/include/glib-2.0 -I/usr/include/glib-2.0/glib.h -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 formattage

pkg-config --cflags --libs glib-2.0 gives me:

-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0

I try with this commande :

gcc -v -H -std=c99 -g -Wall -D_GNU_SOURCE $(pkg-config --cflags glib-2.0) *.c $(pkg-config --libs glib-2.0) -o formattage

But i got this message :

gcc -v -H -std=c99 -g -Wall -D_GNU_SOURCE *.c -o formattage Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) COLLECT_GCC_OPTIONS='-v' '-H' '-std=c99' '-g' '-Wall' '-D' '_GNU_SOURCE' '-o' 'formattage' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1 -quiet -v -imultiarch x86_64-linux-gnu -H -D _GNU_SOURCE main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase main -g -Wall -std=c99 -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccuxfazT.s GNU C (Ubuntu/Linaro 4.8.1-10ubuntu9) version 4.8.1 (x86_64-linux-gnu) compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.1-p2, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"

#include "..." search starts here:
 #include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C (Ubuntu/Linaro 4.8.1-10ubuntu9) version 4.8.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.1-p2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b946adc090b5605f865521be8b22959c
. /usr/include/stdlib.h
.. /usr/include/features.h
... /usr/include/x86_64-linux-gnu/sys/cdefs.h
.... /usr/include/x86_64-linux-gnu/bits/wordsize.h
... /usr/include/x86_64-linux-gnu/gnu/stubs.h
.... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
.. /usr/include/x86_64-linux-gnu/bits/waitflags.h
.. /usr/include/x86_64-linux-gnu/bits/waitstatus.h
... /usr/include/endian.h
.... /usr/include/x86_64-linux-gnu/bits/endian.h
.... /usr/include/x86_64-linux-gnu/bits/byteswap.h
..... /usr/include/x86_64-linux-gnu/bits/types.h
...... /usr/include/x86_64-linux-gnu/bits/wordsize.h
...... /usr/include/x86_64-linux-gnu/bits/typesizes.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
..... /usr/include/x86_64-linux-gnu/bits/byteswap-16.h
.. /usr/include/xlocale.h
.. /usr/include/x86_64-linux-gnu/sys/types.h
... /usr/include/time.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
... /usr/include/x86_64-linux-gnu/sys/select.h
.... /usr/include/x86_64-linux-gnu/bits/select.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.... /usr/include/x86_64-linux-gnu/bits/sigset.h
.... /usr/include/time.h
.... /usr/include/x86_64-linux-gnu/bits/time.h
... /usr/include/x86_64-linux-gnu/sys/sysmacros.h
... /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
.... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.. /usr/include/alloca.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
.. /usr/include/x86_64-linux-gnu/bits/stdlib-float.h
. /usr/include/stdio.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
.. /usr/include/libio.h
... /usr/include/_G_config.h
.... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
.... /usr/include/wchar.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h
.. /usr/include/x86_64-linux-gnu/bits/stdio_lim.h
.. /usr/include/x86_64-linux-gnu/bits/sys_errlist.h
. /usr/include/string.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
main.c:5:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
make: *** [all] Error 1

I think it become more complex

Thanks,

5
  • Are you sure that package libglib2.0-dev is installed? What does dpkg -L libglib2.0-dev |grep glib.h says? Mar 18, 2014 at 14:56
  • @BasileStarynkevitch Yes, /usr/include/glib-2.0/glib.h
    – Poisson
    Mar 18, 2014 at 15:02
  • Reinstall it again: sudo aptitude reinstall libglib2.0-dev Mar 18, 2014 at 15:26
  • @BasileStarynkevitch sudo aptitude reinstall libglib2.0-dev sudo: aptitude: command not found How to fix this
    – Poisson
    Mar 18, 2014 at 15:40
  • Try apt-get instead of aptitude. Also, try to get help by meeting someone face to face. You look lost by many simple issues. Mar 18, 2014 at 19:20

3 Answers 3

4

Order of program arguments to gcc matters a lot (source files should always go before linked libraries).

Compile with

 gcc -std=c99 -g -Wall -D_GNU_SOURCE $(pkg-config --cflags glib-2.0) \
       *.c  \
       $(pkg-config --libs glib-2.0)  -o formattage

But you really want to use a Makefile similar to this one

Of course, you also need to install the libglib2.0-dev package, as reminded by this answer.

BTW: I am (as you probably are) a native French speaker, but on S.O. you should ask questions in English and get error messages in English. Set your LANG environment variable to C with export LANG=C before compiling for Stack Overflow.

4
  • I try like you indicate in your reply : gcc -std=c99 -g -Wall -D_GNU_SOURCE $(pkg-config --cflags glib-2.0) *.c $(pkg-config --libs glib-2.0) -o formattage But it mention : main.c:5:18: fatal error: glib.h: No such file or directory #include <glib.h> ^ compilation terminated. make: *** [all] Error 1
    – Poisson
    Mar 18, 2014 at 12:50
  • As I and user1117884 told you, you need to install the libglib2.0-dev package Mar 18, 2014 at 12:57
  • it is well installed sudo apt-get install libglib2.0-dev Reading package lists... Done Building dependency tree Reading state information... Done libglib2.0-dev is already the newest version. The following packages were automatically installed and are no longer required: kde-l10n-engb kde-l10n-fr Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.
    – Poisson
    Mar 18, 2014 at 13:01
  • Replace gcc with gcc -v -H ; then edit your question to improve it. Mar 18, 2014 at 13:31
0

You need to "link" against the library which implements the interfaces you have included with those -I options. That means adding something like -lglib2.0 to your build command. If the library is not found due to be in a nonstandard location, you will first need to say -L/some/path/to/glib with the location of libglib2.0.

5
  • Note that the compile command already includes -lglib-2.0, and judging by the include paths shown, GLib appears to be installed in the standard location for an Ubuntu system. If an -L option were needed, it would've been included in the output of pkg-config.
    – Wyzard
    Mar 16, 2014 at 13:06
  • Sorry, i don't understand what is the problem in my command, can you explain more please?
    – Poisson
    Mar 16, 2014 at 13:08
  • You mean that i have to change like this: ? gcc -D_GNU_SOURCE -I/usr/include/glib-2.0 -I/usr/include/glib-2.0/glib.h -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -L/usr/share/doc/libglib2.0-0 -lglib-2.0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -g -Wall -Wextra -std=c99 -lm *.c -o formattage
    – Poisson
    Mar 16, 2014 at 13:12
  • Try without the -L/usr/share/doc/libglib2.0-0 first, you may only need the -l option and not -L if GLib is installed in a standard place. See if it works and let us know. If you do end up needing a -L option, the path will not be in doc but in some lib place. Mar 16, 2014 at 13:57
  • No, it is just a matter of order of program arguments to gcc Mar 16, 2014 at 16:58
0

Since the there is no error about not finding -lglib-2.0 we can assume that this was found and passed to the linker. However the symbols are still missing.

I don't know how this could happen. You could check if the file contains the symbols

readelf -Ws /usr/lib/x86_64-linux-gnu/libglib-2.0.so | grep g_hash_table

Otherwise, did I understand right that you installed glib2 from source? Is there a reason you didn't install it using

sudo apt-get install libglib2.0-dev

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.