jiuzhuaxiong / qextserialport

Automatically exported from code.google.com/p/qextserialport
Other
0 stars 0 forks source link

Statically linking QextSerialPort v1.2.0 fails #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to statically compile my application to deploy it but I've got 
multiple linker errors with the statically compiled library of QextSerialPort.

Compiling QextSerialPort with "CONFIG += staticlib" completes successfully, but 
when including the library to any project (CONFIG += static) I get the 
following linker errors:

release/mainwindow.o:mainwindow.cpp:(.text+0x139): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0x171): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0x1e5): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0x215): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0x281): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0x2b1): more undefined references to 
`_imp___ZN14QextSerialPortD1Ev' follow
release/mainwindow.o:mainwindow.cpp:(.text+0x585): undefined reference to 
`_imp___ZN14QextSerialPort11setPortNameERK7QString'
release/mainwindow.o:mainwindow.cpp:(.text+0x5ae): undefined reference to 
`_imp___ZN14QextSerialPort12setQueryModeENS_9QueryModeE'
release/mainwindow.o:mainwindow.cpp:(.text+0x5cc): undefined reference to 
`_imp___ZN14QextSerialPort11setBaudRateE12BaudRateType'
release/mainwindow.o:mainwindow.cpp:(.text+0x5ea): undefined reference to 
`_imp___ZN14QextSerialPort14setFlowControlE8FlowType'
release/mainwindow.o:mainwindow.cpp:(.text+0x608): undefined reference to 
`_imp___ZN14QextSerialPort9setParityE10ParityType'
release/mainwindow.o:mainwindow.cpp:(.text+0x626): undefined reference to 
`_imp___ZN14QextSerialPort11setDataBitsE12DataBitsType'
release/mainwindow.o:mainwindow.cpp:(.text+0x644): undefined reference to 
`_imp___ZN14QextSerialPort11setStopBitsE12StopBitsType'
release/mainwindow.o:mainwindow.cpp:(.text+0x655): undefined reference to 
`_imp___ZN14QextSerialPort10setTimeoutEl'
release/mainwindow.o:mainwindow.cpp:(.text+0x66c): undefined reference to 
`_imp___ZN14QextSerialPort4openE6QFlagsIN9QIODevice12OpenModeFlagEE'
release/mainwindow.o:mainwindow.cpp:(.text+0x67d): undefined reference to 
`_imp___ZN14QextSerialPort5closeEv'
release/mainwindow.o:mainwindow.cpp:(.text+0x6d7): undefined reference to 
`_imp___ZN14QextSerialPort7readAllEv'
release/mainwindow.o:mainwindow.cpp:(.text+0xf0b): undefined reference to 
`_imp___ZN14QextSerialPortC1ENS_9QueryModeE'
release/mainwindow.o:mainwindow.cpp:(.text+0x385e): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0x3b1f): undefined reference to 
`_imp___ZN14QextSerialPortC1ENS_9QueryModeE'
release/mainwindow.o:mainwindow.cpp:(.text+0x6472): undefined reference to 
`_imp___ZN14QextSerialPortD1Ev'
collect2: ld returned 1 exit status

This issue appears on version 1.2.0. I tried with 1.1 and worked as expected 
(exactly same procedure). Maybe it has to do with the addition of the 
enumerator in 1.2.0?
I should also note that version 1.2.0 works as expected when compiled as a 
shared library.

Platform is Windows 7 with mingw32 and statically compiled Qt 4.6.2.

Original issue reported on code.google.com by XavierGr on 1 Jul 2010 at 6:54

GoogleCodeExporter commented 9 years ago
Alas, problem resolved.

After hours of experimentation and reading about linkers and libraries, define 
QEXTSERIALPORT_LIB grabbed my attention. While this way of compiling 
QextSerialPort, as a shared library is correct, (I read it here: 
http://www.lurklurk.org/linkers/linkers.html) for some reason (that I am not 
aware) this fails to resolve while compiling the target application and 
QextSerialPort is compiled statically.

I removed the define QEXTSERIALPORT_EXPORT from the class declaration of 
"qextserialenumerator.h" and "qextserialport.h" and now I've successfully built 
my application statically.

If my theory is incorrect please elaborate on the issue because I am quite 
interested. Note that I haven't yet checked if this modification (along with 
the complete removal of "qextserialport_global.h") affects shared linking of 
the library.

Original comment by XavierGr on 1 Jul 2010 at 10:20

GoogleCodeExporter commented 9 years ago
This issue is not valid any more for current version. Before QextSerialPort 
1.2beta released, your can download the source using Mercurial.

Original comment by dbzhang...@gmail.com on 16 Mar 2012 at 8:35