[Solved] Problem with Qextserialport doesn’t work the library
-
wrote on 26 Aug 2011, 11:20 last edited by
Hi I have problem with the Qextserialport.
I've download the entire file from, http://qextserialport.sourceforge.net/ and than I've open the qextserialport.pro with this code@
PROJECT = qextserialport
TEMPLATE = libCONFIG += debug_and_release
CONFIG += qt
CONFIG += warn_on
CONFIG += threadCONFIG += dll
#CONFIG += staticlibQT -= gui
OBJECTS_DIR = build/obj
MOC_DIR = build/moc
DEPENDDIR = .
INCLUDEDIR = .
HEADERS = qextserialbase.h
qextserialport.h
qextserialenumerator.h
SOURCES = qextserialbase.cpp
qextserialport.cpp
qextserialenumerator.cppunix:HEADERS += posix_qextserialport.h
unix:SOURCES += posix_qextserialport.cpp
unix:DEFINES += TTY_POSIXwin32:HEADERS += win_qextserialport.h
win32:SOURCES += win_qextserialport.cpp
win32:DEFINES += TTY_WINwin32:LIBS += -lsetupapi
DESTDIR = build
#DESTDIR = examples/enumerator/debug
#DESTDIR = examples/qespta/debug
#DESTDIR = examples/event/debugCONFIG(debug, debug|release) {
TARGET = qextserialportd
} else {
TARGET = qextserialport
}unix:VERSION = 1.2.0
@than I make build all in QT 4.7 and in the build directory found qextserialportd.dll and libqextserialportd.a
Than I want run the enumerator example and so I open the file enumerator.pro
@PROJECT = enumerator
TEMPLATE = app
DEPENDPATH += .
INCLUDEPATH += ../..
QMAKE_LIBDIR += ../../buildOBJECTS_DIR = obj
MOC_DIR = moc
UI_DIR = uic
CONFIG += qt warn_on consoleSOURCES += main.cpp
CONFIG(debug, debug|release):LIBS += -lqextserialportd
else:LIBS += -lqextserialportunix:DEFINES = TTY_POSIX
win32:DEFINES = TTY_WIN
@and in the directory of application I copy the two file qextserialportd.dll and libqextserialportd.a
but when run there is the error
:-1: error: cannot find -lqextserialportd
I don't know where is the problem?
-
wrote on 26 Aug 2011, 11:35 last edited by
Weclome to the forum
It could be that the path to the libraries is missing. The details can be found on the "LIBS parameter":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#libs
-
wrote on 26 Aug 2011, 11:45 last edited by
But the path of library is in the 17line with LIBS
@
CONFIG(debug, debug|release):LIBS += -lqextserialportd
else:LIBS += -lqextserialport
@
I have change also
QMAKE_LIBDIR += ../../build
in
QMAKE_LIBDIR += . -
wrote on 26 Aug 2011, 12:00 last edited by
Pathes to libraries are specified with -L, the libraries itself with -l.
-
wrote on 26 Aug 2011, 14:18 last edited by
Okey thk but now I have another problem, when compile this program:
@#include <stdio.h>
#include <qextserialenumerator.h>int main(int argc, char *argv[])
{
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
printf("List of ports:\n");
for (int i = 0; i < ports.size(); i++) {
printf("port name: %s\n", ports.at(i).portName.toLocal8Bit().constData());
printf("friendly name: %s\n", ports.at(i).friendName.toLocal8Bit().constData());
printf("physical name: %s\n", ports.at(i).physName.toLocal8Bit().constData());
printf("enumerator name: %s\n", ports.at(i).enumName.toLocal8Bit().constData());
printf("===================================\n\n");
}
return EXIT_SUCCESS;
}@return this error
C:\Users\Alessio\Desktop\qextserialport-1.2win-alpha\examples\enumerator-build-desktop..\enumerator\main.cpp:11: error: undefined reference to `QextSerialEnumerator::getPorts()'but when I double-click + ctrl on QextSerialEnumerator I read the source file...
-
wrote on 26 Aug 2011, 15:03 last edited by
bq. return this error
C:\Users\Alessio\Desktop\qextserialport-1.2win-alpha\examples\enumerator-build-desktop..\enumerator\main.cpp:11: error: undefined reference to `QextSerialEnumerator::getPorts()’
but when I double-click + ctrl on QextSerialEnumerator I read the source file…It looks like the lib isn't linked! That mean the settings in your pro file are not correct. Show you actual pro file.
-
wrote on 26 Aug 2011, 15:07 last edited by
This is *.pro
@PROJECT = enumerator
TEMPLATE = app
DEPENDPATH += .
INCLUDEPATH += .
QMAKE_LIBDIR += .OBJECTS_DIR = obj
MOC_DIR = moc
UI_DIR = uic
CONFIG += qt warn_on consoleSOURCES += main.cpp
CONFIG(debug, debug|release):LIBS += -Lqextserialportd
else:LIBS += -Lqextserialportunix:DEFINES = TTY_POSIX
win32:DEFINES = TTY_WIN@
and qextserialportd.dll and libqextserialportd.a are in tha same folder of project -
wrote on 26 Aug 2011, 15:15 last edited by
bq. else:LIBS += -Lqextserialport
This doesn't work. You have to set the path to lib i.e "-L/path/to/the/lib" and link the lib i.e. "-lqextserialport".
-
wrote on 29 Aug 2011, 11:55 last edited by
sorry but I don't understand. who is the correct definition of librery...
-
wrote on 29 Aug 2011, 12:12 last edited by
Using LIBS you can pass two types of information
- a list of pathes in which the linker should search for libraries, using -L (uppercase)
- a list of libraries the linker should use, using -l (lowercase)
To add a library you usually have to specifiy both unless the library resides in a system-wide directory (/usr/lib for example).
@
LIBS += -L<path to your library without library name, for example /usr/lib/qt> -l<library name without path to your library, for example qextserialport>
@ -
wrote on 30 Sept 2011, 00:12 last edited by
Here is a long description of what I had to do to get everything to work over the last several days. Hope someone can gain from my pain. :)
When I wanted to build within the serial port files in Creator I had to do the following things on the latest version of QT
You need to copy the file qwineventnotifier_p.h from the source to the correct location as mentioned in other places. (Google it)
Building the SRC files for the DLL (qextserialport.dll, qextserialportd.dll)
Load the src.pro fil into Creator
To build a the correct debug file and never have a problem , I had to change the CONFIG line in the src.pro file fromCONFIG += qt warn_on debug_and_release
To
CONFIG += qt warn_on debugAnd to build a release version I had to use
CONFIG += qt warn_on releaseThe above allowed me to build both versions of the DLL file needed by the other programs. It took two steps but I wasn't changing the code here so it wasn't really an issue and it worked consistantly.
Building the different apps.
The default path to my projects including the “src” files wanted to be src-build-desktop and not just build. This has something to do with my creator
settings I am sure, but I do not know how to fix it.This means in your “enumerator”, “event” and “qespta” .PRO files you need to change the path of the serial library by doing the following.
#QMAKE_LIBDIR += ../../src/build
QMAKE_LIBDIR += ../../src-build-desktop/buildThis would allow me to compile correctly. However, when I wanted to run, I would get run time errors. Some mentioned above
I solved this by copying the (qextserialport.dll, qextserialportd.dll) files to the location of my executable. Once I did this I was able to run correctly.
I probably need to place the DLL files in the system directory but for now, this worked.I hope the above helps others as it took me several hours over several days to figure this out from different threads and trial and error.
Ken
-
wrote on 30 Sept 2011, 00:13 last edited by
One other thing, no spaces in any of the directory names. This can cause weird issues as well.