Custom Widget compilation problem
-
Hello dear developers/specialists/coders/programers.
How are you doing?
I develop custom applications for major platforms and I use QSwitch widget from
[url]http://qt-apps.org/content/show.php/QSwitch?content=72481[/url]
that is inherited from QWidget and uses <QtDesigner/QDesignerExportWidget>
@class QDESIGNER_WIDGET_EXPORT QSwitch : public QWidget
{...}@
I put it to ui generated from Qt Designer at Qt Designer ( QSwitch plugin added to it ),
in Ubuntu I compile my project with that widget well , but on Windows I get the following errors each time compiler meets QSwitch instances:./release\mainwindow.o:mainwindow.cpp:(.text+0x2c6a6): undefined reference to
_imp___ZN7QSwitch8setValueEb' ./release\mainwindow.o:mainwindow.cpp:(.text+0x56b5a): undefined reference to
_imp___ZN7QSwitch8setValueEb'
./release\mainwindow.o:mainwindow.cpp:(.text+0x56c2e): undefined reference to_imp___ZN7QSwitch8setValueEb' ./release\mainwindow.o:mainwindow.cpp:(.text+0x57023): undefined reference to
_imp___ZN7QSwitch8setValueEb'
./release\mainwindow.o:mainwindow.cpp:(.text+0x5707f): undefined reference to_imp___ZN7QSwitch8setValueEb' ./release\mainwindow.o:mainwindow.cpp:(.text+0x5723c): more undefined references to
_imp___ZN7QSwitch8setValueEb' follow
./release\mainwindow.o:mainwindow.cpp:(.text$_ZN14Ui_MainControl7setupUiEP11QMainWindow[Ui_MainControl::setupUi(QMainWindow*)]+0xa2e2): undefined reference to_imp___ZN7QSwitchC1EP7QWidget' ./release\mainwindow.o:mainwindow.cpp:(.text$_ZN14Ui_MainControl7setupUiEP11QMainWindow[Ui_MainControl::setupUi(QMainWindow*)]+0xb5b5): undefined reference to
_imp___ZN7QSwitch8setValueEb'
./release\mainwindow.o:mainwindow.cpp:(.text$_ZN14Ui_MainControl7setupUiEP11QMainWindow[Ui_MainControl::setupUi(QMainWindow*)]+0xb5fa): undefined reference to_imp___ZN7QSwitch7setTypeENS_10SwitchTypeE' ./release\qswitch.o:qswitch.cpp:(.text+0x4f): undefined reference to
_imp___ZN7QSwitch12valueChangedEb'
./release\qswitch.o:qswitch.cpp:(.text+0x79): undefined reference to_imp___ZN7QSwitch12valueChangedEb' ./release\qswitch.o:qswitch.cpp:(.text+0xdd): undefined reference to
_imp___ZTV7QSwitch'
./release\qswitch.o:qswitch.cpp:(.text+0x169): undefined reference to_imp___ZTV7QSwitch' ./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x15): undefined reference to
_imp___ZN7QSwitch16staticMetaObjectE'
./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x26): undefined reference to_imp___ZN7QSwitch16staticMetaObjectE' ./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x59): undefined reference to
_imp___ZN7QSwitch16staticMetaObjectE'
./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0xc3): undefined reference to_imp___ZN7QSwitch11toggleValueEv' ./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x11d): undefined reference to
_imp___ZN7QSwitch7setTypeENS_10SwitchTypeE'
./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x151): undefined reference to_imp___ZN7QSwitch7setTypeENS_10SwitchTypeE' ./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x16e): undefined reference to
_imp___ZN7QSwitch8setValueEb'
./release\moc_qswitch.o:moc_qswitch.cpp:(.text+0x1c7): undefined reference to `_imp___ZN7QSwitch8setValueEb'
collect2: ld returned 1 exit statusPlease help: Why such errors does anybody know? What is wrong/unclear? How to successfully compile on Windows ui with QSwitch widget?
Thanks. -
It is because MS compiler uses symbol visibility rules by default (ie it only exports those symbols that you tell it to). Whereas with GCC you have to explicitly enable this feature by using
@
CONFIG += hide_symbols
@If you add the above to your .pro file it will also fail to link on Linux due to unexported symbols. We use this as it reduces the number of symbols exported in our libs and hence slightly improves application start up time and keeps the private parts of our API private.