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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:23:49  来源:igfitidea点击:

How can I set ccshared=-fPIC while executing ./configure?

c++makefileg++

提问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.infile but it checks several conditions and on the basis of those conditions it assigns -fPICto the CCSHAREDflag.

我从这个错误中发现,我需要用一些标志来构建 Python 2.6,-fPIC. 好的,所以我在configure.in文件中找到了它,但它检查了几个条件,并根据这些条件分配-fPICCCSHARED标志。

What I did was that after all conditions were checked I added the following line to deliberately use CCSHAREDas -fPIC.

我所做的是在检查完所有条件后,我添加了以下行以故意使用CCSHAREDas -fPIC

CCSHARED="-fPIC";

But it did not work..

但它没有用..

How to specify while configuring that I want to set CCSHAREDas -fPIC?

如何在配置时指定我想设置CCSHARED-fPIC

采纳答案by A. Coady

Run configure with --enable-shared. Then -fPICwill 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 -fPICafter CC= gcc -pthread, i.e CC= gcc -pthread -fPICin the Makefile.

我通过添加-fPICafter CC= gcc -pthread,即CC= gcc -pthread -fPIC在 Makefile 中使其工作。

回答by unwind

  1. Run ./configure --help, possibly piping to grep PIC, to see if there's an option to enable this
  2. Try setting the environment variable before running configure, e.g. CCSHARED="-fPIC" ./configure (as a single command, assuming bash)
  1. 运行./configure --help,可能是管道到 grep PIC,看看是否有选项可以启用它
  2. 在运行配置之前尝试设置环境变量,例如 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 joshjdevl

The following has an exampleof passing fPIC to configure

下面有一个通过fPIC来配置的例子

回答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