gcc-4.8.2 doesn't link pthread

724 views Asked by At

all.

Compiling simple stuff using the gcc toolchain for several years, today I ran against a curious phenomenon.

I installed Kubuntu 14.04 to a common desktop i686 machine with gcc 4.8.2 in it. But then, trying to build some well coded stuff pulled out from my local repository, I ran against tons of 'undefined reference to' messages. The code compiles, links und runs well under Ubuntu 11.04 / gcc 4.5.2. I checked the linking process (by -Wl,--verbose to gcc), think it works. It finds all libraries I specify in the link command. An objdump -t myLib.so brings exactly the symbols I'd expect - but the linker doesn't see them.
Checking the pthread library also brings according symbols, except they are suffixed with some @GLIBC... stuff. Didn't check linker/loader tricks so far.

A sample like

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

static void *fooo (void *xxx) {
    char *txt = (char*)xxx;
    printf("My job is to print this :'%s'. Bye now!\n", txt);
    return 0;
 }
 int main (int argc, char *argv[]) {
    pthread_t thd;
    pthread_create(&thd,  NULL, fooo,  "A POSIX thread");
    sleep(1);
    return 0;
 }

runs very well on the old system just saying

gcc -l pthread fooo.c && ./a.out

but breaks at the linking step with 4.8.2.
Any idea would be very welcome.

.M

1

There are 1 answers

4
Mikes On

Thanks to sfrehse, JoachimPileborg et al!

Indeed, success depends on argument order. I knew this fact for static linking, but it is new in processing of shared objects with gcc.

Does someone know what the background of this improvement is? It breaks innumerable build processes, and I guess thousands of tomatoes are being made ready against gcc.gnu.org .....

.M