您尚未登录。

#1 2022-03-29 17:15:25

Melchior
会员
注册时间: 2017-10-28
帖子: 1

ros-noetic-rospack 编译报错,需要添加-fPIC

通过yay -S ros-noetic-rospack 执行安装,以下为部份编译log

[ 22%] Building CXX object CMakeFiles/rospack.dir/src/rospack_backcompat.cpp.o
[ 22%] Building CXX object CMakeFiles/rospack.dir/src/rospack_cmdline.cpp.o
[ 44%] Building CXX object CMakeFiles/rospack.dir/src/utils.cpp.o
[ 44%] Building CXX object CMakeFiles/rospack.dir/src/rospack.cpp.o
[ 55%] Linking CXX shared library devel/lib/librospack.so
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/libtinyxml2.a(tinyxml2.cpp.o): warning: relocation against `_ZN8tinyxml210XMLPrinter10PrintSpaceEi' in read-only section `.text'
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/libtinyxml2.a(tinyxml2.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN8tinyxml210XMLPrinter5WriteEPKcm' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/rospack.dir/build.make:150: devel/lib/librospack.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:316: CMakeFiles/rospack.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
==> ERROR: A failure occurred in build().
    Aborting...
 -> error making: ros-noetic-rospack

在 /etc/makepkg.conf 中修改,加入-fPIC flag:

CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions \
        -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \
        -fstack-clash-protection -fcf-protection"
CXXFLAGS="-fPIC $CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"

之后使用以下命令编译

yay --makepkgconf /etc/makepkg.conf -S ros-noetic-rospack

但是报错信息相同,似乎是没有生效。
kernel信息:

 5.16.11-arch1-1 

离线

#2 2022-03-29 22:28:15

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 7,100
个人网站

Re: ros-noetic-rospack 编译报错,需要添加-fPIC

它可能自己在构建脚本里覆盖了这个设置?

离线

页脚