2011-02-04 43 views
1

我在當前項目中有以下情況:編譯器返回「collect2:Id返回1退出狀態」使用下面的代碼:編譯器錯誤「collect2:Id返回1退出狀態」使用類與QObject(QT 4.7與Qt造物主)

#ifndef BASE_02_H 
#define BASE_02_H 

#include <QtCore> 

class Base_02 
{ 

public: 
    Base_02(); 

    virtual void method()=0; 
}; 

#endif // BASE_02_H 

#include "base_02.h" 
#include <QtCore> 

Base_02::Base_02() 
{ 

} 

//---------------------------------------------------------------------------------------------------------------------------------- 

#ifndef DERIVED_02_H 
#define DERIVED_02_H 

#include <QtCore> 
#include "base_02.h" 

class Derived_02 : public Base_02 
{ 

public: 
    Derived_02(); 
    void method(); 
}; 

#endif // DERIVED_02_H 

#include "derived_02.h" 
#include <QtCore> 

Derived_02::Derived_02() 
{ 

} 

void Derived_02::method() 
{ 
    qDebug() << "Derived_02::method()"; 
} 

//---------------------------------------------------------------------------------------------------------------------------------- 

#ifndef BASE_H 
#define BASE_H 

#include <QtCore> 

class Base : public QObject 
{ 
    Q_OBJECT 

public: 
    Base(Base* p=NULL); 

    virtual void method()=0; 
}; 

#endif // BASE_H 

#include "base.h" 
#include <QtCore> 

Base::Base(Base* p) 
{ 

} 

//---------------------------------------------------------------------------------------------------------------------------------- 

#ifndef DERIVED_H 
#define DERIVED_H 

#include <QtCore> 
#include "base.h" 

class Derived : public Base 
{ 
    Q_OBJECT 

public: 
    Derived(Derived* p=NULL); 
    void method(); 
}; 

#endif // DERIVED_H 

#include "derived.h" 
#include "derived_02.h" 
#include <QtCore> 

Derived::Derived(Derived* p) 
{ 

} 

void Derived::method() 
{ 
    Derived_02 d; 
    d.method(); 
} 

//---------------------------------------------------------------------------------------------------------------------------------- 

#include <QtCore/QCoreApplication> 
#include <QtCore> 
#include "base.h" 
#include "derived.h" 

int main(int argc, char *argv[]) 
{ 
    QCoreApplication a(argc, argv); 



    Derived* derived = new Derived(); 



    return a.exec(); 
} 

編譯器說以下內容:

... 的mingw32-化妝:進入目錄C:/Entwicklung SVN/debug test/dataSenderReceiverExample' C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory C:/ SVN發展協會/調試測試/ dataSenderReceiverExample」 G ++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I「...... \ Qt \ 2010.04 \ qt \ include \ QtCore」-I「...... \ Qt \ 2010.04 \ qt \ include」-I「。 \ dataSenderReceiver「-I」...... \ Qt \ 2010.04 \ qt \ include \ ActiveQt「-I」debug「-I」...... \ Qt \ 2010.04 \ qt \ mkspecs \ win32-g ++ 「-o debug \ main.o main.cpp main.cpp:在函數'int main(int,char **)'中: main.cpp:14:warning:未使用變量'derived' g ++ -enable-stdcall -w,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug \ dataSenderReceiverExample.exe debug/main.o -L「c: \ Qt \ 2010.04 \ qt \ lib「-L ../ dataSenderReceiver/debug -dataSenderReceiver -lQtCored4 mingw32-make [1]:離開目錄C:/Entwicklung SVN/debug test/dataSenderReceiverExample' mingw32-make: Leaving directory C:/ Entwicklung SVN/debug test/dataSenderReceiverExample' ../dataSenderReceiver/debug /libdataSenderReceiver.a(derived.o):C:\Entwicklung SVN \ debug test \ dataSenderReceiver/derived.cpp:14:undefined參考Derived_02::Derived_02()' ../dataSenderReceiver/debug/libdataSenderReceiver.a(derived.o):C:\Entwicklung SVN\debug test\dataSenderReceiver/derived.cpp:15: undefined reference to Derived_02 :: method()' collect2:ld返回1退出狀態 mingw32-make [1]:* [debug \ dataSenderReceiverExample.exe]錯誤1 mingw32-make:* [debug] Error 2 The Prozess「C:/Qt/2010.04/mingw/bin/mingw32-make.exe」wurde mit demRückgabewert%2 beendet。 Fehler BEIM ERSTELLEN DES Projekts dataSenderReceiverExample(ZIEL:桌面) BEIMAusführenDES內置Schritts '製作'

請幫幫忙!

+1

貌似derived.cpp和derived_02.cpp沒有得到comoiled:

在一個.pro文件庫C之前名稱庫B中。你正在使用QtCreator還是你在命令行上運行它?你的makefile是什麼? – 2011-02-04 17:44:56

回答

1
#include "base_02.h" 
#include <QtCore> 

必須是:

#include <QtCore> 
#include "base_02.h" 

然後再編譯!

1

我在下列情況下這個問題:


A是一個可執行文件(網絡控制檯)項目和 B和C庫(FI靜態庫)項目和 一使用B和B使用C.

然後

A必須知道通過pro文件和012乙庫和C庫B必須通過.pro文件瞭解C庫。


在A

。親文件庫C庫是B之前表示爲:

LIBS *= -L"../C/debug" 
LIBS *= -lC 
INCLUDEPATH *= "../C" 

LIBS *= -L"../B/debug" 
LIBS *= -lB 
INCLUDEPATH *= "../B" 

然後

正上方accures描述的錯誤。


解決方案:

LIBS *= -L"../B/debug" 
LIBS *= -lB 
INCLUDEPATH *= "../B" 

LIBS *= -L"../C/debug" 
LIBS *= -lC 
INCLUDEPATH *= "../C" 
相關問題