C++ 如何在执行 ./configure 时设置 ccshared=-fPIC?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/629961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set ccshared=-fPIC while executing ./configure?
提问by ashishsony
I am trying to build Python 2.6 for QGISon RHEL5. During the making of QGIS I get the following error:
我正在尝试在RHEL5上为QGIS构建 Python 2.6 。在制作 QGIS 期间,我收到以下错误:
Linking CXX shared library libqgispython.so
/usr/bin/ld: /usr/local/lib/python2.6/config/libpython2.6.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/python2.6/config/libpython2.6.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [src/python/libqgispython.so.1.0] Error 1
make[1]: *** [src/python/CMakeFiles/qgispython.dir/all] Error 2
make: *** [all] Error 2
What I figure out from this error is that I need to build Python 2.6 with some flag, -fPIC
.
OK, so I found it in the configure.in
file but it checks several conditions and on the basis of those conditions it assigns -fPIC
to the CCSHARED
flag.
我从这个错误中发现,我需要用一些标志来构建 Python 2.6,-fPIC
. 好的,所以我在configure.in
文件中找到了它,但它检查了几个条件,并根据这些条件分配-fPIC
给CCSHARED
标志。
What I did was that after all conditions were checked I added the following line to deliberately use CCSHARED
as -fPIC
.
我所做的是在检查完所有条件后,我添加了以下行以故意使用CCSHARED
as -fPIC
。
CCSHARED="-fPIC";
But it did not work..
但它没有用..
How to specify while configuring that I want to set CCSHARED
as -fPIC
?
如何在配置时指定我想设置CCSHARED
为-fPIC
?
采纳答案by A. Coady
Run configure with --enable-shared
. Then -fPIC
will be included as part of the shared flags.
运行配置--enable-shared
。然后-fPIC
将作为共享标志的一部分包含在内。
回答by Crt
The following worked for me when I ran into this error:
当我遇到此错误时,以下内容对我有用:
make clean
./configure CFLAGS=-fPIC CXXFLAGS=-fPIC
回答by ashishsony
I got it working by adding -fPIC
after CC= gcc -pthread
,
i.e CC= gcc -pthread -fPIC
in the Makefile.
我通过添加-fPIC
after CC= gcc -pthread
,即CC= gcc -pthread -fPIC
在 Makefile 中使其工作。
回答by unwind
- Run
./configure --help
, possibly piping to grep PIC, to see if there's an option to enable this - Try setting the environment variable before running configure, e.g. CCSHARED="-fPIC" ./configure (as a single command, assuming bash)
- 运行
./configure --help
,可能是管道到 grep PIC,看看是否有选项可以启用它 - 在运行配置之前尝试设置环境变量,例如 CCSHARED="-fPIC" ./configure (作为单个命令,假设为 bash)
If neither of those work, you need to read the configure code and understand the conditions it tests for better.
如果这些都不起作用,您需要阅读配置代码并了解它测试的条件以便更好。
回答by evadeflow
As noted elsewhere, running configure with --enable-shared should cause -fPIC to be included in the compiler flags. However, you may still see the "could not read symbols" error if you attempt to do a parallel build using, e.g., 'make -j8'. I had this same error on RHEL 5.2 and it only went away when I removed the '-j8' from my make invocation...
如其他地方所述,使用 --enable-shared 运行配置应该会导致 -fPIC 包含在编译器标志中。但是,如果您尝试使用例如“make -j8”进行并行构建,您可能仍会看到“无法读取符号”错误。我在 RHEL 5.2 上遇到了同样的错误,只有当我从 make 调用中删除“-j8”时它才会消失......
回答by missingsemicolon
rebuilt the openssl with ./config --prefix=/software/bea/openssl/100c --openssldir=/software/bea/openssl/100c/ssl shared -fPIC
使用 ./config --prefix=/software/bea/openssl/100c --openssldir=/software/bea/openssl/100c/ssl shared -fPIC 重建 openssl
and then also it dint work. it gave /usr/bin/ld: links failed. The we modifed the linking part in make file previously it was gcc -Wall -shared -o pwutil.so asciihex.o base64.o bitutils.o dict.o gen_rand.o key_schedule.o md5c.o pdg2_ecb.o pwutils.o random_data.o hexutils.o des3crypt.o blowcrypt.o /software/bea/openssl/1.0.0c/lib/libcrypto.a
然后它也起作用了。它给了 /usr/bin/ld: 链接失败。我们修改了之前make文件中的链接部分是gcc -Wall -shared -o pwutil.so asciihex.o base64.o bitutils.o dict.o gen_rand.o key_schedule.o md5c.o pdg2_ecb.o pwutils.o random_data .o hexutils.o des3crypt.o blowcrypt.o /software/bea/openssl/1.0.0c/lib/libcrypto.a
we changed libcrypto.a to libcrypto.so after rebuilding with shared option and - fPIC
在使用共享选项和 - fPIC 重建后,我们将 libcrypto.a 更改为 libcrypto.so
gcc -Wall -shared -o pwutil.so asciihex.o base64.o bitutils.o dict.o gen_rand.o key_schedule.o md5c.o pdg2_ecb.o pwutils.o random_data.o hexutils.o des3crypt.o blowcrypt.o /software/bea/openssl/1.0.0c/lib/libcrypto.so
gcc -Wall -shared -o pwutil.so asciihex.o base64.o bitutils.o dict.o gen_rand.o key_schedule.o md5c.o pdg2_ecb.o pwutils.o random_data.o hexutils.o des3crypt.o blowcrypt.o /软件/bea/openssl/1.0.0c/lib/libcrypto.so
and it worked
它起作用了
回答by leppie
Isn't that CCFLAGS
? (Haven't been that side of the world for a while.)
那不是CCFLAGS
吗?(有一段时间没有去过世界的那一边了。)
回答by Mohammad Kanan
I got it working with:
我得到它的工作:
./configure --enable-shared --enable-pic