1

While compiling a simple multi-threaded program I can't seem to get the shared objects of pthread linked. I get the following error:

/data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libpthread.a(libpthread.o): In function `sem_open':
(.text+0x77cd): warning: the use of `mktemp' is dangerous, better use `mkstemp'
/cvmfs/cms.cern.ch/slc6_amd64_gcc491/external/gcc/4.9.1-cms/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie
collect2: error: ld returned 1 exit status

I tried reinstalling the glibc, but the error is still present. (using CentOs 6).

The requested minimal example:

#include <future>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    try
    {
        auto test_lambda              = [] (int a, int b, int c) -> void { std::cout << "a: " << a << " b: " << b << " c: " << c << "." << std::endl; };
        std::future<void> test_future = std::async(test_lambda, 1, 2, 3);
        std::chrono::milliseconds milliseconds_100(100);
        while(test_future.wait_for(milliseconds_100) == std::future_status::timeout)
        {
            std::cout << "." << std::endl;
        }
    }
    catch(const std::exception &e)
    {
        std::cout << e.what() << std::endl;
    }
}

Compiler call using gcc 7.1.0:

g++ src/test.cc -std=c++14 -pthread

The error message above is all I get.

If I add -fPIE and -pie, this is the output I get this error:

g++ src/test.cc -std=c++14 -pthread -fPIE -pie

/cvmfs/cms.cern.ch/slc6_amd64_gcc491/external/gcc/4.9.1-cms/bin/ld: /data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libpthread.a(libpthread.o): relocation R_X86_64_32S against `__stack_user' can not be used when making a shared object; recompile with -fPIC
/data/hunyadi/usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../lib64/libpthread.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Adam Hunyadi
  • 1,890
  • 16
  • 32

1 Answers1

0

I managed to get through the error by locally installing gcc 5.3.0 and replacing the libphread.so file by the one generated by it.

Adam Hunyadi
  • 1,890
  • 16
  • 32