QtCreator: Are dynamic library generated really "dynamic" on a Mac - c++

I'm working with QtCreator under MacOS to target iPhone for my applications. Right now, I'm trying got compile a 3rd party library (tinyxml).
My .pro file already works for Linux, Windows and Android targets, I'm just trying to extend it to iOS.
My first surprise is that the generated dynamic library has a .a extension. Shouldn't it be .so (or even `.dynlib)?
My second surprise is that when I generate the library with and without CONFIG += staticlib, it always produces the same binary (actually, the same size, content is reported as being different, but it may only be the SONAME tag). On every other platform, static and dynamic library binaries always have a different size.
Am I doing something wrong? Am I actually always generating the library statically (that would explain the extension being always .a), and if so, how to force the dynamic generation?
Dynamic .pro file:
#Generated by SDE CMake scripts!
CONFIG(release, debug|release) {
TARGET = tinyxml
}
CONFIG(debug, debug|release) {
TARGET = tinyxml-g
}
QT -= core
QT -= gui
CONFIG(debug, debug|release) {
DEFINES += _DEBUG
}
win32: DEFINES += TINYXML_EXPORTS
SOURCES += \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinystr.cpp \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinyxml.cpp \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinyxmlerror.cpp \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinyxmlparser.cpp
TEMPLATE = lib
INCLUDEPATH += \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/./tinyxml
Static .pro file:
#Generated by SDE CMake scripts!
CONFIG(release, debug|release) {
TARGET = tinyxmls
}
CONFIG(debug, debug|release) {
TARGET = tinyxmls-g
}
QT -= core
QT -= gui
CONFIG(debug, debug|release) {
DEFINES += _DEBUG
}
win32: DEFINES += TINYXML_EXPORTS
QMAKE_CXXFLAGS += -DTINYXML_STATIC
SOURCES += \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinystr.cpp \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinyxml.cpp \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinyxmlerror.cpp \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/src/tinyxmlparser.cpp
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += \
/Users/less/Documents/dev/vobs_ext/libcpp/tinyxml/./tinyxml

Got it.
For windows and Android target, default library building is dynamic, so I never had to put anything else than TEMPLATE += lib. On Mac, it's static by default. So, to generate a dynamic library (.dylib), you must request it by adding CONFIG += shared.
This compiles, but crashs upon deployment. I posted this on a different thread: QtCreator for iOS: How to deploy a dylib shared library with my application

Related

How to add an hdf5 to a Qt-Project?

Situation:
I need to add a library (HDF5 in my case) to my qt project.
I know how to code c++ enough for my purposes, but i have no clue about the .pro file. When i try to google my problem or general guides for adding libraries i find lots of answers but understand none of them, because they require more knowledge then i have. They say stuff like "compile it here and there", "add this and that to your system", "use qmake in directory xyz". Can someone please answer the question so that one who only knows a bit of c++ and the green compile & run button of qt understands it? Would be great :-)
What I tired:
I know that there is a wizarb in qt that can add librarys to projects. I used it to add the libraries needed. I added them as "external librarys".
I tried as dynamic or static, i tried adding only the hdf5.lib or the hdf5_cpp.lib too.
Problem:
When I do it as I described above and try to use a function from the added library i always get errors like: undefined reference to H5::Function_Name_xyz.
My .pro looks like (generated by the qt add-library-wizard):
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
#Add external static library "hdf5.lib":
unix|win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Grou/HDF5/1.10.2/lib/hdf5.lib'
#Add external static library "hdf5_cpp.lib"
unix|win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5_cpp
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/hdf5_cpp.lib'
Using:
C++
Qt 5.10.1
MinGW 32bit
HDF5 1.10.2
Windows 7
I had this same issue awhile back. I did the following to correct the linking error.
Make sure you run qmake (Build-> Run qmake) after adding a new library to the .pro file.
Since you are using windows with the pre-built HDF library, you should use the MSVC2015 32 bit Build&Run kit. The pre-built libraries used Microsoft Visual C++ compiler, so to use the HDF libraries you will need to use that compiler.
Per the HDF documentation, you need to list the external libraries first. The following snippit shows my setup using dynamic libraries.
If your using dynamic libraries be sure to add DEFINES += H5_BUILT_AS_DYNAMIC_LIB to your .pro file.
win32: LIBS += -L$$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/lib/' -lszip -lzlib -lhdf5 -lhdf5_cpp
INCLUDEPATH += $$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/include'
DEPENDPATH += $$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/include'

Can't step into/break on my code with qt creator

I have created a project in qt creator with multiple subdirs and am deploying/running it on a beaglebone. Compiles fine, deploys fine, etc.
My issue is that when I try to debug, the only files I can set breakpoints in or step into are those in the same subdir where main.cpp is. Just to test, I duplicated the project with a flat folder structure and can set breakpoints and step into everything.
When the debugger starts up, the debug log tries to set the breakpoints and fails seemingly because it can't find the .cpp files:
"No source file named projectdir/dir1/myclass.cpp.\n"
8045^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="",pending="\"projectdir/dir1/myclass.cpp\":7",times="0",original-location="\"fullpathofprojectdir/dir1/myclass.cpp\":7"}
Whereas it says this for breakpoints in main:
8046^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x0001831c",func="main(int, char**)",file="projectdir/dir2/main.cpp",fullname="fullpathofprojectdir/dir2/main.cpp",line="27",thread-groups=["i1"],times="0",original-location="fullpathofprojectdir/dir2/main.cpp:27"}
Additionally, myclass.cpp doesn't show up in the source files panes either. How can I resolve this?
Here is the setup of my *.pro files:
Top level project file:
TEMPLATE = subdirs
SUBDIRS += \
dir1 \
dir2
unix {
target.path = /home/debian
INSTALLS += target
}
Project file of library (dir1, myclass.cpp, etc):
QT -= gui
TARGET = Common
TEMPLATE = lib
DEFINES += COMMON_LIBRARY
SOURCES += \
myclass.cpp
HEADERS += \
common_global.h \
myclass.h
unix {
target.path = /home/debian/lib
INSTALLS += target
}
CONFIG += debug
Project file containing main:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test
TEMPLATE = app
SOURCES += \
main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Common/release/
-lCommon
else:win32:CONFIG(debug, debug|release): LIBS += -
L$$OUT_PWD/../Common/debug/ -lCommon
else:unix: LIBS += -L$$OUT_PWD/../Common/ -lCommon
INCLUDEPATH += $$PWD/../Common
DEPENDPATH += $$PWD/../Common
target.path = /home/debian
INSTALLS += target
Let me know if there's any other relevant data I forgot to provide. Qt Creator version is 4.5.0 and I'm running it on a 64 bit VM of ubuntu 16.04 if that's relevant.

LNK1104 Error when adding Boost library to Qt project

M'kay so I'm new to Qt and I'm trying to include the boost/filesystem lib to my project. However, when I try to build it, I always get this error:
LNK1104: File "libboost_filesystem-vc140-mt-1_61.lib" cannot be
opened.
Now, I know that this library needs to be build beforehand, so, as described on the Boost-Website I made:
bootstrap
.\b2
and it built just fine. I also used the Qt dialog to add the libary to my project, my .pro-file looks like this:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ProjectName
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
someclass.cpp \
someclass2.cpp
HEADERS += mainwindow.h \
someclass.h \
someclass2.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libarys -llibboost_filesystem-vc140-mt-1_61
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libarys -llibboost_filesystem-vc140-mt-1_61
else:unix: LIBS += -L$$PWD/libarys -llibboost_filesystem-vc140-mt-1_61
INCLUDEPATH += $$PWD/boost
DEPENDPATH += $$PWD/boost
Apparently, I did something wrong, but I can't figure out, WHAT exactly it is. The internet knows the problem, but it seems there's no "easy" solution to it.
Turned out, my project didn't like the lib-version.
I rebuilt my lib files:
>b2 --build-dir="destination/directory" toolset=msvc --build-type=complete link=static threading=multi --with-filesystem stage
Then, I used the library in
release/link-static/runtime-link-static/threading-multi/
Which is:
libboost_filesystem-vc140-mt-s-1_61
And re-ran qmake for the .pro-file. Then built and executed the application and the error is gone.

Qt program fails to run with errors referencing libwinpthread-1

I've made a C++/OpenGL application using the Qt framework, but I cannot to run *.exe file. I always get errors with libwinpthread-1.
I already read articles about that, but all dll's are in the Qt folder, so I don't understand what the problem is. Please take a look at my *.pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
sliceobj.cpp
unix|win32: LIBS += -lOPENGL32
unix|win32: LIBS += -L$$PWD/../../../../5.0.2/mingw47_32/lib/ -lglut32
QMAKE_LFLAGS += -static-libgcc -static-libstdc++
QMAKE_CXXFLAGS_WARN_ON += -Wno-unknown-pragmas
INCLUDEPATH += $$PWD/../../../../5.0.2/mingw47_32/include
win32 {
message("* Using settings for windows")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\opencv\\build\\x86\\vc11\\bin" \
-lopencv_core247\
-lopencv_highgui247\
-lopencv_imgproc247\
-lopencv_video247\
LIBS += -L"C:\\opencv\\build\\x86\\vc11\\staticlib" \
-lopencv_core247\
-lopencv_highgui247\
-lopencv_imgproc247\
-lopencv_video247\
}
Use Dependency Walker to see what exactly your code links against + Which libraries are loaded in runtime. Open your executable with DW and you will see DLL's that are linked against. They need to be present in PATH or beside your executable. Press F7 to start profiling to see which libraries are loaded in runtime. Here as snapshot:
Ok, i know that's not good, but i'm just added this files into debug directory .

How do you tell a Qt app to depend on a Qt lib?

I have a codebase where there are some shared libraries. For example LIB1 does some sort of processing that APP1 needs (depends on).
The qmake *.pro files are setup like the following. There is one root *.pro that is a TEMPLATE=subdirs that lists APP1 and LIB1 as it's subdirs.
LIB1.pro:
TARGET = LIB1
TEMPLATE = lib
QT += core
QT += xml
DESTDIR = path/to/libs/directory
SOURCES += \
File1.cpp \
FileN.cpp
HEADERS += \
File1.h \
FileN.h
APP1.pro:
#------ dependencies ------#
LIBS += -Lpath/to/libs/directory
# LIB1
INCLUDEPATH += path/to/libs/directory/LIB1lib
DEPENDPATH += path/to/libs/directory/LIB1lib
LIBS += -lLIB1
HEADERS = \
FileNplus1.h \
FileM.h
SOURCES = \
FileNplus1.cpp \
FileM.cpp
The problem is that when you compile the root *.pro file LIB1 will compile but APP1 fails to compile with the error QDomElement: No such file or directory because APP1.pro doesn't have QT += xml.
There is a hack that I use but I would like to overcome this hack. The hack involves adding the following line to APP1.pro:
# add this to APP1.pro... let's it compile again
QT += xml
Is there anyway to setup your qmake *.pro files such that, APP1.pro depends on LIB1 without needing to modify APP1.pro to add the QT += xml?
(The reason for this question is let's say you have other libraries that depend on other stuff... I would like to have Qt/Qmake take care of the dependencies like for example the Qt += xml dependency.)
qmake allows you to create your own configuration features. (last paragraph)
So you can create your own feature and move your lib1-linking code to it. You can add QT+=xml here. And in app.pro you'll just write CONFIG += lib1