问题描述
所以我一直在编码的东西在32位,昨天我需要建立一个DLL,我有一些问题。无论如何我解决了他们。 p>
不幸的是,即使我认为一切都工作后,我发现是不是这样,当我移动我的程序和makefile在其他计算机上运行在64位,因为你可以猜猜发生了什么...
所以我的问题是与64位的重定位有关
code> / usr / bin / ld:MyClass.o:重定位R_X86_64_32S对`.rodata'不能在创建共享对象时使用;使用-fPIC重新编译
MyClass.o:无法读取符号:错误值
是我的makefile
MyProgram:main.o chkopts
- $ {CLINKER} -o $ @ $& $ {MYLIB} $ {PETSC_MAT_LIB}
$ {RM} main.o
export LD_LIBRARY_PATH = $ {LIBADD}:$ LD_LIBRARY_PATH
LibMyProgram.so:MyClass .o chkopts
- $ {CLINKER} -shared -Wl,-soname,$ {SONAME} -o $ {VERS} * .o $ {PETSC_MAT_LIB}
mv $ {VERS} $ {LIBADD}
ln -sf $ {LIBADD} $ {VERS} $ {LIBADD} $ {SOWOV}
ln -sf $ {LIBADD} $ {VERS} $ {LIBADD} $ {SONAME}
我试图在CFLAGS,CPPFLAGS甚至LDFLAGS中添加-fPIC。我也尝试在-shared标志之前和之后添加-fPIC。
- $ {CLINKER} -shared -fPIC -Wl ,-soname,$ {SONAME} -o $ {VERS} * .o $ {PETSC_MAT_LIB}
如果我使用CFLAGS = -fPIC,我会得到一个类似的错误:
... / petsc / petsc-3.2-p6 / arch-linux2-cxx-debug / lib / libpetsc.a(err.o ):在创建共享对象时不能使用针对`ompi_mpi_comm_self'的重定位R_X86_64_32;使用-fPIC重新编译。
我已经阅读过所有主题,甚至与我的问题相似,无法解决这个问题。
解决方案是使用 -fPIC
,并链接共享对象与 -shared
。
添加 -fPIC
到 CFLAGS
或 CXXFLAGS
So I've been coding something on 32-bit and yesterday I needed to build a dll and I had a couple of problems with that. Anyway I solved them here.
Unfortunately even if I thought that everything was working after all I found that wasn't the case when I moved my program and makefile on other computer what runs on 64bit, as you can guess what happened...
So my problem is related to relocation because of 64bit
/usr/bin/ld: MyClass.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
MyClass.o: could not read symbols: Bad value
and here is my makefile
MyProgram: main.o chkopts
-${CLINKER} -o $@ $< ${MYLIB} ${PETSC_MAT_LIB}
${RM} main.o
export LD_LIBRARY_PATH=${LIBADD}:$LD_LIBRARY_PATH
LibMyProgram.so: MyClass.o chkopts
-${CLINKER} -shared -Wl,-soname,${SONAME} -o ${VERS} *.o ${PETSC_MAT_LIB}
mv ${VERS} ${LIBADD}
ln -sf ${LIBADD}${VERS} ${LIBADD}${SOWOV}
ln -sf ${LIBADD}${VERS} ${LIBADD}${SONAME}
I've tried to add -fPIC in CFLAGS, CPPFLAGS and even LDFLAGS. I've also tried add -fPIC before and after -shared flag.
-${CLINKER} -shared -fPIC -Wl,-soname,${SONAME} -o ${VERS} *.o ${PETSC_MAT_LIB}
But I'll just get a same error as previously.
If I use CFLAGS = -fPIC I'll get a bit same kind of error which is:
.../petsc/petsc-3.2-p6/arch-linux2-cxx-debug/lib/libpetsc.a(err.o): relocation R_X86_64_32 against `ompi_mpi_comm_self' can not be used when making a shared object; recompile with -fPIC.
I've read about all the topics what are even remotely similar with my problem but I've been unable to figure this out.
The solution was to compile everything with -fPIC
, and link shared objects with -shared
.
Add -fPIC
to CFLAGS
or CXXFLAGS
for make-based projects.
这篇关于重定位R_X86_64_32S针对`.rodata'...在64位平台上编译时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!