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.
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
need .pro files of both app and library to tell something
it seems that the lib is not loaded. Have you tried a static library or myabe a stub test function?
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
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
|
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
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