我想用 OpenMP 卸载编译 C 代码并创建一个动态库 libtest.so
。当我使用以下命令时:
gcc -fPIC -shared -fopenmp -foffload=nvptx-none="-fPIC" test.c -o libtest.so
我收到此错误:
/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 版本是 10.2.0。我不确定我在这里做错了什么,因为-fPIC
它包含在命令中。我想知道是否有可能做我想做的事?
我的test.c
来源只是检查卸载是否有效:
#include <omp.h>
#include <stdio.h>
void test()
{
#pragma omp target teams
{
if (omp_is_initial_device())
printf("on host\n");
else
printf("on target device\n");
}
}