本文介绍了使用 g++ 链接无法搜索 -lstdc++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用其他人的 Makefile 来编译一个非常简单的 c++ 库.生成文件如下:

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

仅供参考,我使用的是 Ubuntu 9.10 64 位.

FYI, I am on Ubuntu 9.10 64bit.

推荐答案

发帖供以后参考,我找到的解决方案是安装 g++-multilib.我在 g++ 版本 4.6.1 上遇到了与 -lstdc++ 相关的相同不兼容问题

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

进一步探索:g++-multilib 是一个虚拟包,它安装了 g++4.6-multilib,而 g++4.6-multilib 又在/usr/lib/gcc/x86_64-linux 下安装了适当的 libstdc++.so-gnu/4.6/32 文件夹.

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.

这篇关于使用 g++ 链接无法搜索 -lstdc++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 13:08