记录一个奇怪的bug:/usr/bin/ld: this linker was not configured to use sysroots

有一个代码需要编译pyflow,用本地的python2编译得挺好,命令如下:

g++ -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/pyflow.o build/temp.linux-x86_64-2.7/src/Coarse2FineFlowWrapper.o build/temp.linux-x86_64-2.7/src/Stochastic.o build/temp.linux-x86_64-2.7/src/OpticalFlow.o build/temp.linux-x86_64-2.7/src/GaussianPyramid.o -L/usr/lib64 -lpython2.7 -o /ssd/gy/iSeeBetter/pyflow/pyflow.so

用anaconda装的新环境下的python3编译就出

/usr/bin/ld: this linker was not configured to use sysroots

命令如下:

g++ -pthread -shared -B /ssd/gy/env/vsr/compiler_compat -L/ssd/gy/env/vsr/lib -Wl,-rpath=/ssd/gy/env/vsr/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/pyflow.o build/temp.linux-x86_64-3.7/src/Coarse2FineFlowWrapper.o build/temp.linux-x86_64-3.7/src/Stochastic.o build/temp.linux-x86_64-3.7/src/OpticalFlow.o build/temp.linux-x86_64-3.7/src/GaussianPyramid.o -o /ssd/gy/iSeeBetter/pyflow/pyflow.cpython-37m-x86_64-linux-gnu.so

/usr/bin/ld: this linker was not configured to use sysroots
collect2: 错误:ld 返回 1

查了半天有说mv /usr/bin/ld 到 /usr/bin/ld.xxx的,结果直接找不到ld了。

最后搞了一晚上,实在没办法了直接模仿本地Python2的命令居然过了。命令如下:

g++ -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-3.7/pyflow.o build/temp.linux-x86_64-2.7/src/Coarse2FineFlowWrapper.o build/temp.linux-x86_64-3.7/src/Stochastic.o build/temp.linux-x86_64-3.7/src/OpticalFlow.o build/temp.linux-x86_64-2.7/src/GaussianPyramid.o -L/usr/lib64 -o /ssd/gy/iSeeBetter/pyflow/pyflow.so

实验发现把中间那些乱七八糟的删掉也可以过:

g++ -pthread -shared build/temp.linux-x86_64-3.7/pyflow.o build/temp.linux-x86_64-3.7/src/Coarse2FineFlowWrapper.o build/temp.linux-x86_64-3.7/src/Stochastic.o build/temp.linux-x86_64-3.7/src/OpticalFlow.o build/temp.linux-x86_64-3.7/src/GaussianPyramid.o -o /ssd/gy/iSeeBetter/pyflow/pyflow.cpython-37m-x86_64-linux-gnu.so

这是说-sysroot=/报错的话,删掉就ok?

g++真是神奇,编译的姿势水平还有待提高......

你可能感兴趣的:(小操作)