0

These both questions did not solve my problem: glib-undefined-reference-to-anything-from-glib and undefined-reference-to-pthread-create

I am writing a personalized version of the snprintf function from glibc-2.21. When I want to link my main.o which is calling the new function snpprintf() then I receive dozens of undefined reference to errors from linker for each call/reference of a glibc-2.21 function.

This is the command:

ar rvs libFaFsprintf.a snpprintf.o vfpprintf.o vsnpprintf.o iovspprintf.o
gcc main.o libFaFsprintf.a -lc -o main

I have my object files in the library libFafsprintf.a - it does not matter if I provide the library or I specify each object file. The source code is compiled without any problem. I tried also to change the order of my library and -lc - nothing helps.

It only works when I use the -static option but I do not want to link libc statically with the executable.

How do I have to link the program?

Community
  • 1
  • 1
Peter VARGA
  • 4,167
  • 3
  • 33
  • 69

1 Answers1

0

How do I have to link the program?

Like this:

gcc main.o libFaFsprintf.a -lglib-2.0 -o main
Employed Russian
  • 182,696
  • 29
  • 267
  • 329
  • as user nemequ realized, I mismatched in the 1st version of the question glib with libc. Usually I do not need to provided the standard C library for the link process – Peter VARGA Mar 01 '15 at 18:19