Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

c++ - OpenMP offloading in a dynamic library fails to compile

I want to compile C code with OpenMP offloading and create a dynamic library libtest.so. When I use the following command:

gcc -fPIC -shared -fopenmp -foffload=nvptx-none="-fPIC" test.c -o libtest.so

I get this error:

/usr/bin/ld: /tmp/ccWnqb5o.target.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status

GCC version is 10.2.0. I'm not sure what I do wrong here since -fPIC is included in the command. I wonder is it even possible to do what I want?

My test.c source just checks if the offloading works:

#include <omp.h>
#include <stdio.h>

void test()
{
  #pragma omp target teams
  {
    if (omp_is_initial_device())
      printf("on host
");
    else
      printf("on target device
");
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I spoke to the GCC developers and it seems to be a bug. They seem to have it resolved for GCC 11, but the fix was not backported. See https://gcc.gnu.org/g:a8b522311beef5e02de15427e924752ea02def2a for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...