Qt Application fails spectacularly - qt

I'm trying to link a Qt application with its libraries and the linker (MinGW) spews hundreds of lines like the following, and I am unsure how to proceed.
cpp: undefined reference to `_Unwind_SjLj_Register'
c:/qt/lib/libQtCore.a(qcoreapplication_win.o)(.text+0x29d):qcoreapplication_win.
cpp: undefined reference to `_Unwind_SjLj_Unregister'
c:/qt/lib/libQtCore.a(qcoreapplication_win.o)(.text+0x38c):qcoreapplication_win.
cpp: undefined reference to `_Unwind_SjLj_Resume'
c:/qt/lib/libQtCore.a(qcoreapplication_win.o)(.text+0x4ce):qcoreapplication_win.
cpp: undefined reference to `_Unwind_SjLj_Register'
c:/qt/lib/libQtCore.a(qcoreapplication_win.o)(.text+0x53e):qcoreapplication_win.
cpp: undefined reference to `_Unwind_SjLj_Unregister'
c:/qt/lib/libQtCore.a(qcoreapplication_win.o)(.text+0x635):qcoreapplication_win.
cpp: undefined reference to `_Unwind_SjLj_Resume'

I don't know... but to me, spewing stuff about Unwind suggests that you have a mismatch between whether the library is compiled with exceptions and your application is compiled with exceptions.
If you want exceptions, make sure you have enabled them by adding the following line in your qmake file:
CONFIG += exceptions
or, if you do not want exceptions, use the opposite
CONFIG -= exceptions
And whatever you do, do not use C++ compiler options to set this yourself.

It's been a while since I did any Qt development, but there were only a couple instances that I remember spewing out huge numbers of messages like this.
Include files for Qt were a
different version than the shared
libraries ... this happened when I
upgraded and for some reason, you
had to manually upgrade the include
files.
The Qt libraries were missing altogether ... I vaguely remember the compiler working, but the linker failing when I first started.
I was doing Qt development targeted at an ARM processor, so I had extra oddities involved when cross-compiling.

2 possible reasons that i know of:
if you try to link gcc4 libraries with a gcc3 linker.
You need the -lstdc++ flag to the end of the compile command

Related

Compiling InterBase support in Qt

I have followed the instructions on http://doc.qt.nokia.com/stable/sql-driver.html#qibase for compiling Interbase support into Qt, and made sure all of my libraries are in the right place. qmake runs successfully, but when I run nmake, I get a series of undefined reference errors in qsql_ibase.cpp. If I open up the .pro in Qt Creator and hover over one of the functions that is throwing the undefined reference errors and follow the symbol (F2), it takes me to the ibase.h file where it is declared. Is it throwing the undefined reference errors because there is no function definition? If that is the case, why isn't it giving me any errors about a missing library?
Output example:
Creating library file: debug\libqsqlibased4.a
debug/qsql_ibase.o: In function getIBaseError':
C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../../sql/drivers/ibase
/qsql_ibase.cpp:80: undefined reference toisc_sqlcode'
C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../../sql/drivers/ibase
/qsql_ibase.cpp:85: undefined reference to isc_interprete'
debug/qsql_ibase.o:C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../.
./sql/drivers/ibase/qsql_ibase.cpp:406: undefined reference toisc_dsql_free_st
atement'
debug/qsql_ibase.o:C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../.
./sql/drivers/ibase/qsql_ibase.cpp:421: undefined reference to isc_create_blob2
'
debug/qsql_ibase.o:C:\QtSDK\QtSources\4.7.4\src\plugins\sqldrivers\ibase/../../.
./sql/drivers/ibase/qsql_ibase.cpp:427: undefined reference toisc_put_segment'
This continues for many more errors, all undefined references.
That really sounds like the first issue mentioned under the "Troubleshooting" section of the page to which you link above:
You should always use client libraries that have been compiled with
the same compiler as you are using for your project. If you cannot get
a source distibution to compile the client libraries yourself, you
must make sure that the pre-compiled library is compatible with your
compiler, otherwise you will get a lot of "undefined symbols" errors.
Some compilers have tools to convert libraries, e.g. Borland ships the
tool COFF2OMF.EXE to convert libraries that have been generated with
Microsoft Visual C++.
Which compiler are you using to compile Qt, and where did you get the Interbase libraries? You also need to make sure those libraries can be found at link time. If you look at the output of your compiler, it should show you all the link directories in which it is searching (in addition to any globally defined, like PATH in Windows.) If the folder with your Interbase library is listed, it is probably that the compiler versions aren't matching.
Sorry for raising so old theme, but I found a solution and want to share with it. The problem is that macro ISC_EXPORT was not defined in Interbase's SDK due to conditional compilation defines. See details here - Howto build Interbase plugin for Qt by MinGW

Qt VTK link fails

I am trying to build a simple Qt app with the VTK libraries included, but I am getting a link error:
The Reg....A functions are unresolved (like RegOpenKeyExA) referenced
from vtksys.lib.
I think that I have Advapi32.lib linked.
Am I supposed to specify ASCII in the build somehow or is a library missing or what?
What does your CMakeLists.txt look like? You should have a line like:
target_link_libraries(YourProgram QVTK ${VTK_LIBRARIES})
What is your compiler used to build VTK? And Qt? Are them identical? It seems most linked problems between Qt and VTK are due to mismatching library files.

Accessing NI-VISA from Qt C++ 4.7

I am developing a Windows (7) application using Qt (4.7.0) to call some methods in a DLL (NI visa32.dll) to communicate with instruments through the GPIB port. The manufacturer's header file is also available (visa.h).
In the project file, I tried adding the path and library reference to the original places where the files are located at as:
INCLUDEPATH += "C:/Program Files/National Instruments/Shared/CVI/Include"
LIBS += "C:/Windows/System32/visa32.dll"
but, I get the compilation error:
collect2: ld returned 1 exit status
Following the instructions in Importing a DLL into Qt, I created a "visa.a" from the "visa32.dll", and copied them to a subfolder "visa/lib", and added the path and library to the project file:
INCLUDEPATH += visa/include
LIBS += -Lvisa/lib
LIBS += -lvisa.a
I tried also with -lvisa or -lvisa.dll, but in all the cases I get also another compilation error saying that the -lvisa, -lvisa.a or -lvisa.dll is not found. I edited the original header file "visa.h", and prefixed with Q_DECL_IMPORT every object in the file, and also made sure that the extern "C" statement be present.
I include the reference to the header file in the application as:
#include "visa.h"
and note that the compiler does recognize the referenced objects belonging to the visa.h file.
Any help to solve this compilation error will be greatly appreciated.
I also tried with Visual C++ (2010) following the instructions of DLL References in Visual C++. In this case, I do not get any compilation error, but linking errors. For example:
AgiE364X.obj: error LNK2019: unresolved external symbol
"extern "C" long __stdcall viClose(unsigned long)"
being viClose a called method in NI-VISA.
I would prefer to use Qt C++ instead of Visual C++, though.
Thanks in advance.
I'm not sure since I'm new to Qt myself but here are some guesses: I noticed you have a space in INCLUDEPATH string. Also, LIBS += -Lvisa/lib has a capitol L (is this correct?). I'm not saying this is your problem but perhaps worth a try. The last thing that comes to mind is that if you're using Qt Creator only partially type #include "visa.h" and see if auto complete can complete it for you. If it can, than prob the rest is OK. Trigger auto-complete with Ctrl+Space. I've noticed that when I mess up the paths auto-complete is a good gauge for this sort of thing.
There are two types of library of VISA provided by NI: the one is compiled by borland c++, the other is compiled by microsoft vc++.
As for Qt, you can use Qt which should be compiled by MSVC, to link the visa32.lib which is compiled by MSVC too. And it MUST link .lib instead of .dll, The MSVC library of VISA is in "C:\Program Files\IVI Foundation\VISA\WinNT\lib\msc" by default.
The include directory is C:\Program Files\IVI Foundation\VISA\WinNT\include by default.
In fact, the above information can be known from VISA example after you install the device driver.

Qt3Support and mingw static linker error

I had a problem at first compiling Qt static on windows, QTBUG-11249
When configured with "-no-qt3support", the build completes fine.
i did that and compiled successfully, but i get the same errors when i try to compile my application.
e:\Qt\2010.04-static\qt\lib/libQtGui.a(qapplication.o):qapplication.cpp:(.text+0x8e0f): undefined reference to _imp___Z21qt_call_post_routinesv'
e:\Qt\2010.04-static\qt\lib/libQtGui.a(qapplication.o):qapplication.cpp:(.text+0x9443): undefined reference to_imp___Z21qt_call_post_routinesv'
e:\Qt\2010.04-static\qt\lib/libQtGui.a(qapplication.o):qapplication.cpp:(.text+0x9a6b): undefined reference to _imp___Z21qt_call_post_routinesv'
e:\Qt\2010.04-static\qt\lib/libQtGui.a(qwhatsthis.o):qwhatsthis.cpp:(.text+0xfc): undefined reference to_imp___Z21qDeleteInEventHandlerP7QObject'
i'm using the mingw version packed with qt, when i use the shared qt dir it works, but when i try to link against the static one it fails.
now i guess it has something to do with -no-qt3support, but i have no idea how to use that in my project.

Undefined references when trying to link Qt app with my static library

I have a static library that I have built with MinGW, I am trying to link to that library from a Qt application. I keep getting linker errors caused by one of the object files in the library. This file actually declares a couple of Boost headers, one for use of shared_ptr and the other so I can make a class noncopyable. I believe using this boost functionality is what is causing the issue but I have no idea why. If I comment out the classes in the Qt app that use the class defined in the file, the Qt app links fine. This is the error part of the output:
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x10a):
undefined reference to
`__gxx_personality_sj0'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x12f):
undefined reference to
`_Unwind_SjLj_Register'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x203):
undefined reference to
`_Unwind_SjLj_Resume'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x20e):
undefined reference to
`_Unwind_SjLj_Unregister'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x226):
undefined reference to
`__gxx_personality_sj0'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x24b):
undefined reference to
`_Unwind_SjLj_Register'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x31f):
undefined reference to
`_Unwind_SjLj_Resume'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x32a):
undefined reference to
`_Unwind_SjLj_Unregister'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0xc):
undefined reference to
`__gxx_personality_sj0'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0x31):
undefined reference to
`_Unwind_SjLj_Register'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0xfb):
undefined reference to
`_Unwind_SjLj_Resume'
C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0x106):
undefined reference to
`_Unwind_SjLj_Unregister' collect2: ld
returned 1 exit status
One other thing to mention is that I am using a pointer to implementation in this class.
Any help would be much appreciated.
Solved:
I figured out that I had an older version of GCC in my path that was beng included before my MinGW supplied GCC version. The old version was included in a GNUStep package that I had from awhile back. I think that configuration of these different versions was causing problems. Thanks to kemiisto, who was on the right track in solving the issue.
It seems that your static library was linked against one MinGW distribution (i.e. 3rd version) but you try to link your application with this library using other MinGW distribution (i.e. 4th version which is distributed with binary Qt). You should rebuild your library using the same MinGW which you use for your application development.
Update
May be it's another well known problem. Take a look at this topic. You probably have 2 different folders with Qt libs
C:\Qt\2009.05\bin;C:\Qt\2009.05\qt\bin
in your path too. Libraries in the first folder (...\bin) compiled with VS2008 and libraries in the second one (...\qt\bin) compiled with MinGW. The items in path variable are looked up when your application starts. Suddenly the folder with "wrong" libraries exists before the folder with correct item in your path variable. What you can do is to copy QtCore4.dll, QtGui4.dll and other libraries that you need to folder with your application executable. Hope this helps.
Some links about this problem:
#qtforum.org
#some blog post (in Russian =))
Just in case anyone else has this problem: my project rebuild was using .o files from a previous build. I changed compilers in between.
Turns out that when I rebuilt the same project, the new compiler didn't build new .o files, so they were missing some key info. After deleting the old files and rebuilding, the error was fixed.
I assume rebuilding from scratch, without the delete, would work the same.
you may have used gcc instead of g++. gcc is a C compiler. but g++ is a c++ compiler.
just make sure to use g++ if you have .cpp files.

Resources