You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

ad5xj

Trainee

  • "ad5xj" is male
  • "ad5xj" started this thread

Posts: 129

Location: Louisiana

  • Send private message

1

Thursday, October 1st 2009, 6:01pm

Error Undefined reference when using shared lib

Hello everyone

I am having a problem converting a working project to separate shared libaries and application. I have created a shared libarary and added the code to make it a library:

In the library global:

Source code

1
2
3
4
5
6
7
#include <QtCore/qglobal.h>

#if defined(OPENMODEM_LIBRARY)
#  define OPENMODEMSHARED_EXPORT Q_DECL_EXPORT
#else
#  define OPENMODEMSHARED_EXPORT Q_DECL_IMPORT
#endif


In the library public interface:

Source code

1
2
3
4
5
6
7
8
9
#include "openModem_global.h"
//////  EXPORTED CLASS DEFINITION  //////
class OPENMODEMSHARED_EXPORT openModem : public QObject
{
    Q_OBJECT

public:
    openModem(QObject *parent=0);
    ~openModem();


When I try to use this library in the app I get this:

Error Undefined reference to _imp_ZN9openModemC1EP7QObject

What am I overlooking?
AD5XJ

2

Friday, October 2nd 2009, 9:24am

need .pro files of both app and library to tell something

Huupke

Beginner

  • "Huupke" is male

Posts: 10

Location: Netherlands

Occupation: Software Engineer

  • Send private message

3

Friday, October 2nd 2009, 12:06pm

it seems that the lib is not loaded. Have you tried a static library or myabe a stub test function?

ad5xj

Trainee

  • "ad5xj" is male
  • "ad5xj" started this thread

Posts: 129

Location: Louisiana

  • Send private message

4

Friday, October 2nd 2009, 7:19pm

Error Undefined reference when using shared lib

Here is the .pro code from both lib and app


Library .pro:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
TEMPLATE = lib 
DEFINES += OPENMODEM_LIBRARY
QT -= gui
CONFIG = qt thread warn_on debug
win32:CONFIG += dll windows
unix:CONFIG += shared x11
TARGET = openModem
MOC_DIR = moc
OBJECTS_DIR = obj
SOURCES += . . .

win32:SOURCES += . . .


HEADERS += . . .
win32:HEADERS += . . .

win32:LIBS += -lwinmm



Application .pro

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
TEMPLATE = app 
TARGET = MultiQ
QT +=
DEPENDPATH = .
INCLUDEPATH = .
CONFIG = qt exceptions thread warn_on debug
win32:CONFIG += windows
unix:CONFIG += unix x11
MOC_DIR = moc
OBJECTS_DIR = obj
DESTDIR = debug
SOURCES += . . .

HEADERS += . . .

win32:LIBS += -L../openModem/openModem.dll
unix:LIBS += -llibopenModem.a
RESOURCES += application.qrc

Hope this helps
The application is a working application and all modules are the same as in the working app. The only difference is the one noted. I am missing something where the exported symbols are concerned. The linker finds my DLL but the symbols are not resolved.
AD5XJ

5

Saturday, October 3rd 2009, 11:14am

RE: Error Undefined reference when using shared lib

try
Library .pro:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
TEMPLATE     = lib
TARGET       = openmodem
DEFINES     += OPENMODEM_LIBRARY

QT          -= gui

MOC_DIR      = moc
OBJECTS_DIR  = obj

SOURCES     += ...

HEADERS     += ...

win32: {
        SOURCES     += ...
        HEADERS     += ...
}

Application .pro

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
TEMPLATE     = app
TARGET       = multiq

DESTDIR      = debug
MOC_DIR      = moc
OBJECTS_DIR  = obj

DEPENDPATH   = .
INCLUDEPATH  = .

SOURCES     += ...

HEADERS     += ...

RESOURCES   += application.qrc

LIBS        += -L../openmodem -lopenmodem

ad5xj

Trainee

  • "ad5xj" is male
  • "ad5xj" started this thread

Posts: 129

Location: Louisiana

  • Send private message

6

Sunday, October 4th 2009, 7:53pm

Error Undefined reference when using shared lib

This yields more errors in every use of the library objects:

error: invalid use of undefined type `struct openModem'

AD5XJ

ad5xj

Trainee

  • "ad5xj" is male
  • "ad5xj" started this thread

Posts: 129

Location: Louisiana

  • Send private message

7

Sunday, October 4th 2009, 8:16pm

Error Undefined reference when using shared lib

Problem solved!

There was a small typo error (lower case where upper case was needed) in the app code that references the objects.

Thanks for your help!
AD5XJ