2016-06-12 16 views
0

Ich habe zwei Projekte in Qtcreator: BiosPatcher - der Code & BiosPatcherTest - googletest Unit-Tests für BiosPatcher-Code. Tipps von hier:wie Projektheader-Dateien aus einem anderen Projekt importieren und es als Bibliothek für Qtcreator Projekte verwenden

multiple main declaration in qtcreator project which uses googletest

Wie Quellen aus einem Projekt in einem anderen und verbinden builded Projekt als Bibliothek in QtCreator zu einem anderen QtCreator Projekt importieren?

BiosPatcher Projekt hat:

BiosPatcher\src\bios\Bios.{cpp, hpp} class 

und in BiosPatcherTest ich habe Test:

#include "src/bios/Bios.hpp" //not works 
... 
TEST(BiosTest, testReadMethodReadsFromBiosIO) { 
MockBiosIO mockBiosIO; 
EXPECT_CALL(mockBiosIO, readAsBytes()) 
    .Times(AtLeast(1)); 

MockReentrantLock mockReentrantLock; 
MockBiosVector mockBiosVector; 
MockPatch mockPatch; 
MockLog mockLog; 

Bios bios; 
bios.setBiosIO(&mockBiosIO); 
bios.setLock(&mockReentrantLock); 
bios.setBiosBytesVector(&mockBiosVector); 
bios.setLog(&mockLog); 
bios.setPatch(&mockPatch); 

bios.read(); 

}

Antwort

0

Zuerst müssen Sie BiosPatcher C++ Shared Library-Projekt. Nach, müssen Sie fügen Sie einfach BIOSPATCHER_LIBRARY zu Klassendeklaration

diese

class BiosPatcher 
{ 

Notwendigkeit dieses

class BIOSPATCHERSHARED_EXPORT BiosPatcher 
{ 

ersetzt werden und, nachdem es nur Ihre Bibliothek kompilieren und beinhalten gleiche Header in Ihrem zweiten Projekt, und fügen Sie zur Verknüpfung generiert .lib Datei.

DEPENDPATH''= . ../BiosPatcher 
INCLUDEPATH ''= ../BiosPatcher 
LIBS''= -L../BiosPatcher/debug -lBiosPatcher 

Als ich IDE-Bibliothek-Projekt in meinem Qt Creator erstellt mit dem Namen BiosPatcher, erstellt automatisch biospatcher_global.h Datei, die containts BIOSPATCHERSHARED_EXPORT defination. Diese Datei muss in allen Bibliothekskopfzeilen enthalten sein. Sie sehen, wenn definiert BIOSPATCHER_LIBRARY dann BIOSPATCHERSHARED_EXPORT wird definiert als Q_DECL_EXPORT, sonst Q_DECL_IMPORT. BIOSPATCHER_LIBRARY ist in der Bibliothek .pro definiert, dh wenn Sie diese Header aus einem anderen Projekt einfügen, wird die Klasse aus der kompilierten Bibliothek importiert.

#ifndef BIOSPATCHER_GLOBAL_H 
#define BIOSPATCHER_GLOBAL_H 

#include <QtCore/qglobal.h> 

#if defined(BIOSPATCHER_LIBRARY) 
# define BIOSPATCHERSHARED_EXPORT Q_DECL_EXPORT 
#else 
# define BIOSPATCHERSHARED_EXPORT Q_DECL_IMPORT 
#endif 

#endif // BIOSPATCHER_GLOBAL_H 

das Lesen Sie auch: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application