Cannot link static library after upgrading gcc to version 10

127 views Asked by At

I am developing a C application that uses the expat XML library. I have built expat from source and installed it under path /opt/libexpat-2.4.8. I build my program with something like (simplified wrt. the original):

gcc -I/optlibexpat-2.4.8/include -L/opt/libexpat-2.4.8/lib -lexpat -o myorogram myprogram.c

Everything worked fine for almost a year, until I upgraded my GNU/Linux distribution last week. My distribution has now the following compiler version:

gcc (Debian 10.2.1-6) 10.2.1 20210110

When I try to compile the source using the new toolchain, I get lots of linker errors such as:

/usr/bin/ld: /tmp/[...].o: in function [...] undefined reference to `XML_ParserCreate'

On the other hand, if I look at /opt/libexpat-2.4.8/lib/libexpat.a:

$ nm /opt/libexpat-2.4.8/lib/libexpat.a | grep XML_ParserCreate

I get

00000000000037a0 T XML_ParserCreate
0000000000003790 T XML_ParserCreate_MM
00000000000037b0 T XML_ParserCreateNS

So: the symbol is in the library but ld cannot find it.

I copied the source code and the compiled expat library without any change to another computer that has an older toolchain (gcc 8.3.0), and everything works fine there.

I have also tested on a third computer that has the newer toolchain (same GNU/Linux distribution, same version) and I get the same errors there.

So I suppose that maybe some compile options have changed in gcc-10, but I have no clue as to where to look for them. I am using basic options like -I, -L and -l.

Do you have any hints?

0

There are 0 answers