PDA

View Full Version : Library B implements library a



Delphi
15th July 2013, 15:44
Hi,

I'm having some trouble with libraries. I am having an undefined reference.
C:file:-1: error: undefined reference to `_imp___ZTV13OrderStrategy'
C:file:-1: error: release/LibraryB.o: bad reloc address 0x1 in section `.text$_ZN13LibraryBD1Ev[__ZN13LibraryByD1Ev]'


Library A is compliled and located in its own release folder.
Library B implements an interface from library A.


Which header need i to use as header for the base of InterfaceAImp?
I have chosen for Library A - > InterfaceA.h with an unified LIBRARYA_LIBRARY. So the header will be class Q_DECL_IMPORT InterfaceA. somthing is going wrong but I dont know what.

Any help is appreciated,
Delphi

Library A class:



#if defined(LIBRARYA_LIBRARY)
# define INTERFACESHARED_EXPORT Q_DECL_EXPORT
#else
# define INTERFACESHARED_EXPORT Q_DECL_IMPORT
#endif

class INTERFACESHARED_EXPORT InterfaceA
{

public:
virtual ~InterfaceA(){}
virtual QString* run() =0;
};


Library B *.pro

QT -= gui

TARGET = Implementation
TEMPLATE = lib

DEFINES += IMPLEMENTATION_LIBRARY

DEPENDPATH += . ../LibraryA
INCLUDEPATH += ../LibraryA
LIBS+= -L../LibraryA/release -lLibraryA


library B class





#if defined(LIBRARYB_LIBRARY)
# define IMPLEMENTATIONSHARED_EXPORT Q_DECL_EXPORT
#else
# define IMPLEMENTATIONSHARED_EXPORT Q_DECL_IMPORT
#endif

#include "InterfaceA" // header file from Library A, dir: ../LibraryA
class IMPLEMENTATIONSHARED_EXPORT InterfaceAImp : public InterfaceA
{

public:
InterfaceAImp
virtual ~InterfaceAImp(){}
virtual QString* run(){return "Hello world";}
};

Santosh Reddy
15th July 2013, 16:02
InterfaceAImp constructor is missing, and more over the link error and code you show does not match.

Delphi
15th July 2013, 23:00
my apologies, the copy past work is sloppy.

the class InterfaceAImp as a constructor like InterfaceAImp(){}
both the error messages happen on OrderStrategy, in this example that library is called libraryB.


When i use the Library A class file without INTERFACESHARED_EXPORT it is compiling fine. But i will need to declare an interface imput when using it from a library right?
So will the problem be on the sided of LibraryA or B?

Santosh Reddy
16th July 2013, 04:53
What is OrderStrategy?
Where is it used?
Where is it defined?

Delphi
16th July 2013, 08:33
The error messages:
C:\??\ordersuggestie\orderSuggestie.cpp:-1: error: undefined reference to `_imp___ZTV13OrderStrategy'
C:\??\ordersuggestie\orderSuggestie.cpp:-1: error: undefined reference to `_imp___ZTV13OrderStrategy'
:-1: error: release/orderSuggestie.o: bad reloc address 0x1 in section `.text$_ZN13OrderStrategyD1Ev[__ZN13OrderStrategyD1Ev]'
collect2.exe:-1: error: error: ld returned 1 exit status

It seems it has nothing to do with OrderStrategy.
"libraryA" compiled fine but is missing some classes / functions. How is this possible.

I removed all classes except 1. to make an easy example. When i compile this project, I am get a library (dll) of 23Kb. There are no O or cpp file generated and Dependency walkers shows not functions inside.

the 3 files (https://www.dropbox.com/s/bujd0bj7sqjym81/LibraryA.zip)

*.Pro

QT += gui sql

TARGET = Domain
TEMPLATE = lib

DEFINES += DOMAIN_LIBRARY

SOURCES +=

HEADERS +=\
domain_global.h \
orderStrategy.h


domain_global.h


#ifndef DOMAIN_GLOBAL_H
#define DOMAIN_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(DOMAIN_LIBRARY)
# define DOMAINSHARED_EXPORT Q_DECL_EXPORT
#else
# define DOMAINSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // DOMAIN_GLOBAL_H


orderStrategy.h


#ifndef ORDERSTRATAGY_H
#define ORDERSTRATAGY_H

#include "domain_global.h"

#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQueryModel>

class DOMAINSHARED_EXPORT OrderStrategy
{

public:
virtual ~OrderStrategy(){}
virtual QSqlQueryModel* genereerOrder(QSqlDatabase db) =0;
};
#endif // ORDERSTRATAGY_H

Delphi
16th July 2013, 12:40
Fixed: Some .H file did not have a .cpp file. Destructor was implemented in H file.

For some reason those classes did not end up in the library(dll).

Santosh Reddy
16th July 2013, 13:01
Some .H file did not have a .cpp file. Destructor was implemented in H file.
If the implementation is in header (.h) file then the the the project including this library header will generate it's own version of function, and will not be in dll.