使用 g++ 进行链接搜索 -lstdc++ 失败
我正在尝试使用别人的 Makefile 来编译一个非常简单的 C++ 库。 makefile 如下:
JNIFLAGS=-O2 -pthread -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux
all:
rm -f ../dist/libUtils.so
g++ $(JNIFLAGS) -c -m32 -o com_markets_utils_dates_NativeTime.o com_markets_utils_dates_NativeTime.cpp
g++ $(JNIFLAGS) -c -m32 -o DateUtil.o DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libUtils.so DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libNativeTime.so DateUtil.o com_markets_utils_dates_NativeTime.o
编译正常,但链接器抱怨:
...
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [all] Error 1
仅供参考,我使用的是 Ubuntu 9.10 64 位。
I'm trying to use someone else's Makefile to complile a very simple c++ library. The makefile is as follows:
JNIFLAGS=-O2 -pthread -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux
all:
rm -f ../dist/libUtils.so
g++ $(JNIFLAGS) -c -m32 -o com_markets_utils_dates_NativeTime.o com_markets_utils_dates_NativeTime.cpp
g++ $(JNIFLAGS) -c -m32 -o DateUtil.o DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libUtils.so DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libNativeTime.so DateUtil.o com_markets_utils_dates_NativeTime.o
This compiles fine, but the linker complains:
...
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [all] Error 1
FYI, I am on Ubuntu 9.10 64bit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
发布供将来参考,我找到的解决方案是安装 g++-multilib。我在 g++ 版本 4.6.1 上遇到了与 -lstdc++ 相关的相同不兼容问题
进一步探测:g++-multilib 是一个虚拟包,它安装了 g++4.6-multilib,而 g++4.6-multilib 又安装了相应的 libstdc++.so 在 /usr/lib/gcc/x86_64-linux-gnu/4.6/32 文件夹下。
Posting for future reference, a solution I found was to install g++-multilib. I had the same incompatible problem relating to -lstdc++ on g++ version 4.6.1
On further probing: g++-multilib is a dummy package which installed g++4.6-multilib which in turn installed the appropriate libstdc++.so under the /usr/lib/gcc/x86_64-linux-gnu/4.6/32 folder.
回答我自己的问题:
这个解决方案似乎有点黑客,您需要为该库的 32 位版本创建一个符号链接(在安装 @nos 的答案中提到的软件包之后):
完成此操作后,链接器将自动找到要使用的正确库。
Answering my own question:
Ths solution seems to be a bit of a hack, you need to create a symlink for the 32 bit version of the library (after installing the packages mentioned in @nos's answer):
Once you've done this, the linker will automagically find the correct library to use.
您似乎正在 64 位计算机上编译 32 位库,但是不存在 32 位版本的 libstdc++。
尝试 apt-get install ia32-libs libc6-i386 libc6-dev-i386 lib32gcc1 lib32stdc++6
(顺便说一句。您正在生成 .so ,您也应该在编译 .cpp 文件时指定 -fPIC )
It seems you're compiling a 32 bit library on a 64 bit machine, however a 32 bit version of libstdc++ is not present.
Try apt-get install ia32-libs libc6-i386 libc6-dev-i386 lib32gcc1 lib32stdc++6
(btw. you're producing a .so , you should specify -fPIC when compiling your .cpp files as well)
安装 multilib 应该会有所帮助,但请注意,您需要指定与 GCC 版本相对应的版本号,例如:
Installing multilib should help, but pay attention that you need to specify the version number corresponding to GCC version like: