gpt4 book ai didi

c++ - 为存档而构建的静态库,它不是被链接的体系结构 (x86_64)

转载 作者:IT老高 更新时间:2023-10-28 21:37:47 25 4
gpt4 key购买 nike

当我尝试编译两个不同的程序时,我遇到了似乎相同的问题。他们每个人都首先创建一个静态库,然后是链接该库的主应用程序。我正在使用 gcc 4.7.2 开发 Mac OS Mavericks。

计划 1

这就是我运行 make 时发生的情况:

首先,库 libfeat.a 已创建,但我收到警告:

ar rc ../lib/libfeat.a imgfeatures.o utils.o sift.o kdtree.o minpq.o xform.o
ranlib ../lib/libfeat.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: ../lib/libfeat.a the table of contents is empty (no object file members in the library define global symbols)

然后,在编译应用程序时,它说它不能使用该库,因为它不是为相同的架构 (x86_64) 构建的:

gcc -O3 -I../include `pkg-config --cflags opencv` `pkg-config --cflags gtk+-3.0` `pkg-config --cflags gsl` siftfeat.c -o ../bin/siftfeat -L../lib -lfeat `pkg-config --libs opencv` `pkg-config --libs gtk+-3.0` `pkg-config --libs gsl`
ld: warning: ignoring file ../lib/libfeat.a, file was built for archive which is not the architecture being linked (x86_64): ../lib/libfeat.a

如果我运行 lipo,我会得到:

$ lipo -info ../lib/libfeat.a 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: archive with no architecture specification: ../lib/libfeat.a (can't determine architecture for it)

方案 2

我在使用另一个执行相同操作的程序时遇到了同样的问题:首先创建一个库,然后再使用它。

这是创建库时的输出:

ar crv libsba.v1.5.a sba_levmar.o sba_levmar_wrap.o sba_lapack.o sba_crsm.o sba_chkjac.o
r - sba_levmar.o
r - sba_levmar_wrap.o
r - sba_lapack.o
r - sba_crsm.o
r - sba_chkjac.o
ranlib libsba.v1.5.a

这是应用程序:

c++ -o bundler -O3 -Wall -fpermissive  -I../lib/imagelib -I../lib/sfm-driver -I../lib/matrix -I../lib/5point -I../lib/sba-1.5 -I../lib/ann_1.1_char/include  -L../lib -L../lib/ann_1.1_char/lib \
-D__NO_UI__ -D__BUNDLER__ -D__BUNDLER_DISTR__ BaseApp.o BundlerApp.o keys.o Register.o Epipolar.o Bundle.o BundleFast.o MatchTracks.o Camera.o Geometry.o ImageData.o SifterUtil.o BaseGeometry.o BundlerGeometry.o BoundingBox.o BundleAdd.o ComputeTracks.o BruteForceSearch.o BundleIO.o ProcessBundle.o BundleTwo.o Decompose.o RelativePose.o Distortion.o TwoFrameModel.o LoadJPEG.o -limage -lsfmdrv -lsba.v1.5 -lmatrix -lz -llapack -lblas -lcblas -lminpack -lm -l5point -ljpeg -lANN_char -lgfortran
ld: warning: ld: warning: ignoring file ../lib/libsba.v1.5.a, file was built for archive which is not the architecture being linked (x86_64)

在这种情况下,lipo 确实告诉我该库的架构是 x86_64:

$ lipo -info lib/libsba.v1.5.a 
input file lib/libsba.v1.5.a is not a fat file
Non-fat file: lib/libsba.v1.5.a is architecture: x86_64

发生了什么事?

最佳答案

一个可能的原因是使用 GNU ar(1)/ranlib(1)而不是 Xcode 工具链提供的那些。运行which -a arwhich -a ranlib查看您在 $PATH 中的内容.

例如:

$ which -a ranlib
/usr/local/bin/ranlib
/usr/bin/ranlib

$ /usr/local/bin/ranlib --version
GNU ranlib (GNU Binutils) 2.28.51.20170105
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

$ /usr/bin/ralib --version
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: unknown option character `-' in: --version
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib [-sactfqLT] [-] archive [...]

同样适用于 ar .如果你和我一样拥有/usr/local/bin前文/usr/bin$PATH , 使用 /usr/local/bin 中的 GNU 工具和 /usr/bin 中的 Xcode ,您可以使用以下方法修复它:

cd /usr/local/bin
mv ar gar
ln -s /usr/bin/ar ar
mv ranlib granlib
ln -s /usr/bin/ranlib ranlib

关于c++ - 为存档而构建的静态库,它不是被链接的体系结构 (x86_64),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22107616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com