2009-09-22 28 views
17

iPhoneプロジェクトをコンパイルする際に次のエラーが発生しました。誰も私がそれを修正する方法を知っていますか? "ONEDのためのvtableの:: MultiFormatUPCEANReader" は、から参照:MultiFormatUPCEANReader.o LDに __ZTVN4oned23MultiFormatUPCEANReaderE $ non_lazy_ptr:記号(S) collect2はが見つかりません:ldはvtable for ..コンパイルエラーから参照されました。xcode

答えて

38

1つの終了ステータスを返し、問題がでていることと思われましたclass MultiFormatUPCEANReader私はコンストラクタとデストラクタを宣言しましたが、デストラクタのボディを書かなかったので、これはこの厄介な問題を引き起こしていました。これは誰かがコンパイルエラーを解決するのに役立ちます。これは情報がほとんどないひどいコンパイラエラーです!

+4

Iは同意する、ひどいエラーメッセージ。私は基本クラスで仮想メソッドの実装がないため、これを持っていた。 – Nick

+1

この質問にお答えいただきありがとうございます - それは "参照元のvtable"の最初のGoogleの結果として来ました - 私は多くの時間を節約しました。 – noamtm

+0

あなたは命の恩人です! – cyclotrojan

12

一般的に、vtableの問題がありません:C++ FAQ Lite 23.10。 - 私はちょうど行ったよう

If you get a link error of the form "Error: Unresolved or undefined symbols detected: virtual table for class Fred," you probably have an undefined virtual member function in class Fred.

The compiler typically creates a magical data structure called the "virtual table" for classes that have virtual functions (this is how it handles dynamic binding). Normally you don't have to know about it at all. But if you forget to define a virtual function for class Fred, you will sometimes get this linker error.

Here's the nitty gritty: Many compilers put this magical "virtual table" in the compilation unit that defines the first non-inline virtual function in the class. Thus if the first non-inline virtual function in Fred is wilma(), the compiler will put Fred's virtual table in the same compilation unit where it sees Fred::wilma(). Unfortunately if you accidentally forget to define Fred::wilma(), rather than getting a Fred::wilma() is undefined, you may get a "Fred's virtual table is undefined". Sad but true.

+0

私の人生を救いました:) – name

+0

リンクが死んでいます – Martin

4

1は、CPPファイルにメソッドの定義の前にクラス名を入れることを忘れたときに同じエラーが発生する可能性があります。インターネットのアーカイブから

。そして、それはxcodeのことではありません。私はcmakeをビルドに使用していて、gccはコンパイラとして使用しています(通常はxcodeと同じです)。

+0

あなたはまったく正しいです – WINSergey

3

私にとっては、同じプロジェクトがうまくコンパイルされているので、XCodeのことでした。

私のファイルFoo.hには、.cppファイルで実装されているコンストラクタとデストラクタがありました。しかし、私はFoo.hにある別のクラスも持っていました。その実装は.cppではなくFoo.hにありました。 だから私はXcodeプロジェクト - >ターゲット - > "TragetName" - > BuildSourcesにFoo.hファイルを追加しなければならず、この問題は解決されました。

これが役に立ちます。例えば

+0

今日は「ソースをコンパイル」と呼ばれていますが、完璧に働いています! – Mrlenny

5

私の場合、それが宣言が、派生クラスで実装されていない(より具体的にvtableの内の最初の仮想メソッド)した基本クラスで定義された純粋仮想メソッドであった:

class Base 
{ 
public: 
    virtual int foo() = 0; 
    virtual int bar() = 0; 
}; 

class Derived : public Base 
{ 
public: 
    Derived() {} 
    ~Derived() {} 

    virtual int foo(); // <-- causes this obscure linker error 
    virtual int bar() {return 0;} 
}; 
関連する問題