Results 1 to 7 of 7

Thread: Library B implements library a

  1. #1
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Library B implements library a

    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:
    Qt Code:
    1. #if defined(LIBRARYA_LIBRARY)
    2. # define INTERFACESHARED_EXPORT Q_DECL_EXPORT
    3. #else
    4. # define INTERFACESHARED_EXPORT Q_DECL_IMPORT
    5. #endif
    6.  
    7. class INTERFACESHARED_EXPORT InterfaceA
    8. {
    9.  
    10. public:
    11. virtual ~InterfaceA(){}
    12. virtual QString* run() =0;
    13. };
    To copy to clipboard, switch view to plain text mode 

    Library B *.pro
    Qt Code:
    1. QT -= gui
    2.  
    3. TARGET = Implementation
    4. TEMPLATE = lib
    5.  
    6. DEFINES += IMPLEMENTATION_LIBRARY
    7.  
    8. DEPENDPATH += . ../LibraryA
    9. INCLUDEPATH += ../LibraryA
    10. LIBS+= -L../LibraryA/release -lLibraryA
    To copy to clipboard, switch view to plain text mode 

    library B class

    Qt Code:
    1. #if defined(LIBRARYB_LIBRARY)
    2. # define IMPLEMENTATIONSHARED_EXPORT Q_DECL_EXPORT
    3. #else
    4. # define IMPLEMENTATIONSHARED_EXPORT Q_DECL_IMPORT
    5. #endif
    6.  
    7. #include "InterfaceA" // header file from Library A, dir: ../LibraryA
    8. class IMPLEMENTATIONSHARED_EXPORT InterfaceAImp : public InterfaceA
    9. {
    10.  
    11. public:
    12. InterfaceAImp
    13. virtual ~InterfaceAImp(){}
    14. virtual QString* run(){return "Hello world";}
    15. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Library B implements library a

    InterfaceAImp constructor is missing, and more over the link error and code you show does not match.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Library B implements library a

    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?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Library B implements library a

    What is OrderStrategy?
    Where is it used?
    Where is it defined?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Library B implements library a

    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

    *.Pro
    Qt Code:
    1. QT += gui sql
    2.  
    3. TARGET = Domain
    4. TEMPLATE = lib
    5.  
    6. DEFINES += DOMAIN_LIBRARY
    7.  
    8. SOURCES +=
    9.  
    10. HEADERS +=\
    11. domain_global.h \
    12. orderStrategy.h
    To copy to clipboard, switch view to plain text mode 

    domain_global.h
    Qt Code:
    1. #ifndef DOMAIN_GLOBAL_H
    2. #define DOMAIN_GLOBAL_H
    3.  
    4. #include <QtCore/qglobal.h>
    5.  
    6. #if defined(DOMAIN_LIBRARY)
    7. # define DOMAINSHARED_EXPORT Q_DECL_EXPORT
    8. #else
    9. # define DOMAINSHARED_EXPORT Q_DECL_IMPORT
    10. #endif
    11.  
    12. #endif // DOMAIN_GLOBAL_H
    To copy to clipboard, switch view to plain text mode 

    orderStrategy.h
    Qt Code:
    1. #ifndef ORDERSTRATAGY_H
    2. #define ORDERSTRATAGY_H
    3.  
    4. #include "domain_global.h"
    5.  
    6. #include <QtSql/QSqlDatabase>
    7. #include <QtSql/QSqlQueryModel>
    8.  
    9. class DOMAINSHARED_EXPORT OrderStrategy
    10. {
    11.  
    12. public:
    13. virtual ~OrderStrategy(){}
    14. virtual QSqlQueryModel* genereerOrder(QSqlDatabase db) =0;
    15. };
    16. #endif // ORDERSTRATAGY_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by Delphi; 16th July 2013 at 11:00.

  6. #6
    Join Date
    Apr 2013
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Library B implements library a

    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).
    Qt 5.1.0 x86 - Windows 7 x64

  7. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Library B implements library a

    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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 3
    Last Post: 20th December 2012, 12:48
  2. How do I point to a C++ library (non Qt library)
    By ChrisL1234 in forum Newbie
    Replies: 5
    Last Post: 7th June 2012, 23:51
  3. Dynamic library on Mac, Library not loaded
    By grayfox in forum Newbie
    Replies: 2
    Last Post: 2nd July 2011, 02:42
  4. Replies: 2
    Last Post: 19th February 2011, 11:26
  5. Replies: 4
    Last Post: 18th December 2009, 18:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.