0

Fedora/gcc でプログラム (Windows/MSVC で正常に動作) をコンパイル/実行しようとしています。コンパイルは問題ありませんが、リンクに問題があるようです。症状と`__gxx_personality_sj0 へのこの記事の未定義の参照に基づいて、問題はコンパイラ/リンカーのアーキテクチャ タイプの不一致である可能性があるように思われました。無論、私は専門家ではないので、

  • yum list | egrep gcc|g++|c++とを使用してyum remove見つけたものをすべてアンインストールしました
  • それから走っyum install gcc gcc-c++た。

ノート:

  • 以下に表示されるすべての出力は、上記の手順の後です。
  • gcc 出力の最後の行は次のとおりです。collect2: ld returned 1 exit status
  • コードはクリーンにコンパイルされ、警告/エラーはありません。
  • ほとんどすべての未定義の参照は、namespace std
  • ソースファイルは 1 つMain.C(およびヘッダーは 2 つ) しかありません。

思いつく限りの情報を提供しようとしましたが、さらに情報が必要な場合はお知らせください。

[root@myTestMachine kash]# ls -Altr
total 44K
-rw-r--r--. 1 root root 3.5K Sep 11 11:34 .bashrc
-rw-r--r--. 1 root root 2.6K Sep 11 13:50 MyCommon.h
-rw-r--r--. 1 root root 3.5K Sep 11 14:01 Main.cpp
-rw-r--r--. 1 root root  26K Sep 11 14:02 sort.h
-rw-r--r--. 1 root root   80 Sep 11 14:26 a.cpp
[root@myTestMachine kash]#
[root@myTestMachine kash]# gcc -c -std=c++0x Main.cpp
[root@myTestMachine kash]# echo $?
0
[root@myTestMachine kash]#
[root@myTestMachine kash]# rm Main.o
[root@myTestMachine kash]#
[root@myTestMachine kash]# gcc -std=c++0x Main.cpp
/tmp/cckR4oL1.o: In function `main::{lambda(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const':
Main.cpp:(.text+0x270): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'

..... LOTS of other such undefined refs; see complete list on pastebin link below .....

Main.cpp:(.text._ZSt10_ConstructISsISsEEvPT_DpOT0_[_ZSt10_ConstructISsISsEEvPT_DpOT0_]+0x37): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)'
/tmp/cckR4oL1.o:(.eh_frame+0x1cb): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[root@myTestMachine kash]#

ここで完全な gcc 出力: http://pastebin.com/PvycFHQM


[root@myTestMachine kash]# uname -a
Linux myTestMachine 3.1.0-7.fc16.i686.PAE #1 SMP Tue Nov 1 20:53:45 UTC 2011 i686 i686 i386 GNU/Linux
[root@myTestMachine kash]#
[root@myTestMachine kash]# yum list gcc gcc-c++
Loaded plugins: langpacks, presto, refresh-packagekit
Installed Packages
gcc.i686                                               4.6.3-2.fc16                                           @updates
gcc-c++.i686                                           4.6.3-2.fc16                                           @updates
[root@myTestMachine kash]#
[root@myTestMachine kash]# rpm -qa | grep gcc
gcc-4.6.3-2.fc16.i686
libgcc-4.6.3-2.fc16.i686
arm-gp2x-linux-gcc-4.1.2-12.fc15.i686
gcc-c++-4.6.3-2.fc16.i686
arm-gp2x-linux-gcc-c++-4.1.2-12.fc15.i686
[root@myTestMachine kash]#
[root@myTestMachine kash]# rpm -qa | grep g++
[root@myTestMachine kash]#
[root@myTestMachine kash]# rpm -qa | grep c++
libsigc++20-2.2.10-1.fc16.i686
libstdc++-devel-4.6.3-2.fc16.i686
libstdc++-4.6.3-2.fc16.i686
gcc-c++-4.6.3-2.fc16.i686
arm-gp2x-linux-gcc-c++-4.1.2-12.fc15.i686
[root@myTestMachine kash]#
[root@myTestMachine kash]# rpm -qa | grep ld
rpm-build-libs-4.9.1.2-1.fc16.i686
libldb-1.1.0-1.fc16.i686
openldap-2.4.26-1.fc16.1.i686
[root@myTestMachine kash]# rpm -qa | grep -w ld
[root@myTestMachine kash]#
[root@myTestMachine kash]# ld -version
GNU ld version 2.21.53.0.1-6.fc16 20110716
Copyright 2011 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) a later version.
This program has absolutely no warranty.
[root@myTestMachine kash]#
[root@myTestMachine kash]# gcc --version
gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@myTestMachine kash]#
4

1 に答える 1

6

これをしないでください:

gcc -std=c++0x Main.cpp

代わりにこれを行います:

g++ -std=c++0x Main.cpp

または、代わりに次のようにします。

gcc Main.cpp -lstdc++

肝心なのは、リンク段階で「g++」または「-lstdc++」を使用していることを確認してください。コンパイル段階ではどちらのフロントエンドも使用できます。

于 2012-09-11T19:53:10.290 に答える