So I have made two libraries with gcc and ar: libwa.a and libws.a.
When I link them using -l flag in my project. I get this error:
/usr/bin/ld: .../lib/libws.a(bhns.c.o): in function `atoi': bhns.c:(.text+0x0): multiple definition of `atoi'; .../lib/libwa.a(axx.c.o):axx.c:(.text+0x0): first defined here /usr/bin/ld: .../lib/libws.a(bhns.c.o): in function `atol': bhns.c:(.text+0x20): multiple definition of `atol'; .../lib/libwa.a(axx.c.o):axx.c:(.text+0x20): first defined here /usr/bin/ld: .../lib/libws.a(bhns.c.o): in function `atoll': bhns.c:(.text+0x30): multiple definition of `atoll'; .../lib/libwa.a(axx.c.o):axx.c:(.text+0x30): first defined here /usr/bin/ld: .../lib/libws.a(bhns.c.o): in function `bsearch': bhns.c:(.text+0x40): multiple definition of `bsearch'; .../lib/libwa.a(axx.c.o):axx.c:(.text+0x40): first defined here /usr/bin/ld: .../lib/libws.a(bhns.c.o): in function `atof': bhns.c:(.text+0xc0): multiple definition of `atof'; .../lib/libwa.a(axx.c.o):axx.c:(.text+0xc0): first defined here It seems that when I include <stdlib.h> header, it also defines atoi and those other functions as extern __inline, which provides one definition of those symbols per each library. For that reason there's are multiple definitions linker error.
Is there any way of going around this? I don't think this is expected behavior.
stdlib.hdoes not provide an external definition for any function, except possibly if your code has undefined behavior. For example, if it messes with reserved identifiers, such as__inline, then that might cause you all manner of grief.