linking mac framework to qt creator - c++

I have a project that uses SystemConfiguration.Framework.
I've been using xcode, where adding the framework is quite easy, just add it to xcode project's framework. But now, I need my project to be cross platform, so I'm using QT Creator as a single IDE, for Windows and Mac. The problem is that I don't know how to tell QT Creator how to link to the systemConfiguration.framework. The header from the framework are correctly included, no problem there... just when is ending the compilation it complains that some symbols where not found, i.e, the symbols that are exported from the systemconfiguration.framework...
Does anyone knows or can help me to set up the Qt creator project to link agains that framework, please?

I assume the project itself is using Qt i.e. it is using .pro files to configure things like include paths and library/framework paths? If so then you just need to update the relevant .pro file to add the framework.
See the qmake docs for more detail. The gist of it is to add
QMAKE_LFLAGS += -F/path/to/framework/directory/
and
LIBS += -framework TheFramework

I found a solution which works with Qt 5.6 here:
https://doc.qt.io/qt-5/qmake-platform-notes.html#creating-frameworks
Using Frameworks
qmake is able to automatically generate build rules for linking
against frameworks in the standard framework directory on macOS,
located at /Library/Frameworks/.
Directories other than the standard framework directory need to be
specified to the build system, and this is achieved by appending
linker options to the LIBS variable, as shown in the following
example:
LIBS += -F/path/to/framework/directory/
The framework itself is linked in by appending the -framework options and the > name of the framework to the LIBS variable:
LIBS += -framework TheFramework

Related

QT build errors with plugin / sdk library (autodesk fbx sdk)

I have just learned to configure my VS console app to use the Autodesk fbx plugin (vs2017). I am trying now to embed it in QT creator but it does not seem to work: the project does not build because of undefined references. obviously it is no able to attach one of the sdk's components but I don't know why this is happening.
in my .pro file, I have added the following:
LIBS += "E:/misc/fbx sdk/2020.0.1/lib/vs2017/x86/release/libfbxsdk.lib"
LIBS += "E:/misc/fbx sdk/2020.0.1/lib/vx2017/x86/release/libfbxsdk.dll"
INCLUDEPATH += "E:/misc/fbx sdk/2020.0.1/include"
DEPENDPATH += "E:/misc/fbx sdk/2020.0.1/lib/vs2017/x86"
This should have added the libfbxsdk.lib runtime lib to the project, and I also referenced the .dll there but that couldn't be the issue because the error would fire at run time.. Includes should be fine because the headers are included properly as well. Do you have any idea why this might be happening?
Here are the errors:
Do I understand correctly that these must have been declared in the .lib? But QT still does not see them?
I finally got this working. First, my attempt at a logical explanation...
The fbx sdk package that I have downloaded is specifically for Visual Studio 2017. Additionally, I aim at 32 bit. Now, Visual Studio's native compiler is MSVC, and this is what defines the toolchain including linking, compilation etc. QT's default compiler (at least for me) is g++. I cannot give you any good explanation but that was the reason why the linker in QT has been failing: you have to compile and link the sdk with the toolchain it was designed for. That is, with MSVC compiler and, for me, 32 bit architecture.
The steps:
1. You have to install a version of QT compiled with MSVC. I installed Qt 5.12.2 MSVC 2017 32-bit (2017 because I have downloaded the SDK for VS 2017)
2. Having installed this, you have to select the appropriate toolchain in the QT creator: this can be done in kits. Go to kits and directly select there the MSVC kit. It should be available after you have installed everything from (1.). Note that other kits previously active have to be deactivated by right-clicking on them and choosing the option. The kits can be managed in the 'Projects' tab.
3. After that, you can include your paths to the project AND link the libs - statically or dynamically. If you link dynamically, you have to manage the .dll as well (I placed it in the folder with the build of the project. If you link statically, you have to link all relevant .libs - for example, I first skipped the xml.lib which has lead to linker errors again.
See my .pro includes / adds below:
INCLUDEPATH += "E:/misc/fbx sdk/2020.0.1/include"
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/release/' -llibfbxsdk
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/debug/' -llibfbxsdk
INCLUDEPATH += $$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/release'
DEPENDPATH += $$PWD/'../../../misc/fbx sdk/2020.0.1/lib/vs2017/x86/release'
I have achieved the library includes with the QT wizard: right-click on the project for that, and choose 'Add libraries'. Then choose 'External library', specify the path, and choose to link it dynamically or statically.
If you happen to have run into the same problem and have questions re/ this, feel free to drop a line in comments.

z.lib problems while porting qt creator projet to windows

I am trying to port a Qt5.9 project from Mac to Windows 10.
I was able to compile the project easily in a ubuntu installation.
While trying to build it for windows, i had problems with finding zlib include headers with
#include<zlib.h>
That i corrected after following answers here on Stack to
#include<QtZlib/zlib.h>
Now i have problems in LINK phase, it can not open the file z.lib
Problem is i downloaded zlib packages, builds, source code and could not find a z.lib. Only different named libs. Searching in google i could only find people with the same problem, z.lib is not one of the libs included in zlib installation.
This is my project file:
TEMPLATE = app
QT += qml quick widgets websockets
CONFIG += c++11
SOURCES += \
main.cpp \
api.cpp \
app.cpp
HEADERS += \
api.hpp \
app.hpp
RESOURCES += qml.qrc
LIBS += -lz
I tried putting all possible dll and lib files in the project folder. None of them is named z.lib though.
The symbols for zlib are already part of the qt libraries. As long as you do not try to link the zlib explicitly it should work. At least it does work for me.
add to your project file:
!win32 {
LIBS += -lz
}
I managed to solve my problem updating my Qt installation to use MinGw 5.3 32bit. I was using VisualStudio 2015 as the compiler before.
Only changing the compiler to MinGw (g++) 5.3 made everything work with the same pro file i posted in the original question. Thanks everybody who tried to help!

Adding static library link line to my Qt project file makes no difference

I've read a lot of "duplicate" posts on the subject of statically linking your Qt project on windows to statically built Qt core libs. However, I was left very confused when I compared it to what I am seeing. What I gathered from all the posts is if you already have the statically built Qt libs (which I seem to have here C:\Qt\5.4\mingw491_32\lib) all you need to do is to include a line like so
LIBS += -LC:/Qt/5.4/mingw491_32/lib -lQt5Core -lQtGui
in your .pro file without having to specify -static anywhere. However, this line seems to do exactly ZERO. When I comment it out my project builds exactly the same way without it. The exe is the same size and when I try to run it from command prompt a runtime error appears in a dialog box saying it can't find Qt5Core.dll. Its clearly still linking dynamically. What am I doing wrong? Here is the whole .pro file.
#QT +=
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testproj
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
QMAKE_CXXFLAGS +=-std=c++11
#LIBS += -LC:/Qt/5.4/mingw491_32/lib -lQt5Core
I clearly have major holes in my understanding of how Qt linking works on windows. Any help on this topic is highly appreciated.
Qt does not distribute static builds.
It seems you only have a dynamic build and got confused by the .lib/.a files. On Windows, there are 3 types of library:
Dynamic libraries (.dll)
Static libraries (.a or .lib depending on the toolchain)
Import libraries (.a or .lib depending on the toolchain)
Import libraries are only used with dynamic libraries. The import libraries are used by the linker when generating the exe, while the dynamic libraries are used at run time.
So if you have Qt5Core.lib or Qt5Core.a does not mean you have a static build of Qt.
To build your own static version of Qt, I suggest your read Building a static Qt for Windows using MinGW on Qt's wiki.
The major hint is: no matter how Qt is built, you shouldn't need to change anything in the project that uses Qt. Qmake and the configuration files in a given Qt install govern how the applications that use Qt are linked against Qt.
Another hint: a given Qt installation can be either configured for static or dynamic linking, not both. Thus any sort of configuration on the project end is superfluous: a given Qt install already "knows" how to link Qt correctly.
Any given .pro file should work whether Qt is linked statically or dynamically. You should not have any static-linking-specific entries. Remove the LIBS line from the project.
If your executable is dynamically linked, the only reason is that you're using a dynamically linked build of Qt. You should make a static build yourself first, and then use it with your project, and your executable will be statically linked against Qt. It's that simple.
Qt Creator doesn't care about these details either. All it does is invoke qmake and then the make tool. But each qmake is specific to a particular installation of Qt, and that qmake is configured to access that installation's configuration files, and those files contain the data needed to select the proper linking etc. So all of the information is specific to a particular kit one is using, and specifically to the Qt "version" that kit is using (really, a Qt installation because there can be multiple installs of the same version, configured differently).

How to properly link third party library (like protobuf) into Qt Creator project?

I have succesfully managed to build Protobuf on WIndows XP using MSYS 1.0 (C:\msys\) and MinGW from Qt 5.2 bundle (C:\Qt\Qt5.2.1\) following these steps.
The result is that I have following 8 files in C:\msys\local\lib
libprotobuf-8.dll (7,9MB)
libprotobuf-lite-8.dll (0,9MB)
libprotobuf-lite.a(1,1MB)
libprotobuf-lite.dll.a (0,3MB)
libprotobuf-lite.la (1KB)
libprotobuf.a (10,3MB)
libprotobuf.dll.a (2MB)
libprotobuf.la (1KB)
Which is the correct file I need to include in my Qt project, where to place it and how to properly link it (there are three choices in "Include library wizard" in Qt Creator). What would be the best practice ?
Just use:
LIBS += -lprotobuf ...
etc. I would place the dlls next your binary if they are only used by your project.

Using SFML with Qt creator?

I've recently began learning the SFML API for learning purposes but it seems to me like it only supports Codeblocks IDE and Visual Studio. I dislike both IDEs for my own ideas and I like the IDE that comes with Qt instead.
Is it possible to basically use SFML within the Qt creator?
EDIT:
I know some of you may some day find this on google, after struggling for 8 days to set up sfml to work with qt creator I've found the sollution:
step 1: Download the VS version of SFML from the website (NOT codeblocks version)
step 2: copy the DLLs from C:\SFML-1.6\lib to your system32 directory
step 3: open qt creator, make a plain C++ project, open your .pro file and add these lines:
INCLUDEPATH += C:\SFML-1.6\include
LIBS += C:\SFML-1.6\lib\sfml-system.lib \
C:\SFML-1.6\lib\sfml-window.lib \
C:\SFML-1.6\lib\sfml-graphics.lib \
C:\SFML-1.6\lib\sfml-audio.lib \
C:\SFML-1.6\lib\sfml-network.lib
And you're done!
Short answer: Yes.
The IDE doesn't really matter all that much. The compiler does. Depending on the compiler used by Qt Creator, you download the appropriate SFML package. Most likely the MinGW based version will work just fine with your default install of Qt Creator. (I believe that relies on MinGW?)
All that then remains to be done is place SFML in its own directory and making sure that you set up the correct paths in your Qt Creator project. There's not much to it really.
I know i'm a little bit late to the party but:
SFML library is 100% compatible with qtcreator especially qmake.
Download SFML from https://www.sfml-dev.org/download/sfml/2.5.1/ . Bottom right minGW (You most likely have mingw on qt)
Place it somewhere you will know where it is. I usually put it in "C:/SFML-2.5.1"
There's a simple copy pasta you can add to your qmake '.pro' file:
INCLUDEPATH += "C:/SFML-2.5.1/include"
LIBS += -L"C:/SFML-2.5.1/lib"
CONFIG(debug, debug|release){
LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-system-d -lsfml-window-d
} else {
LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-system -lsfml-window
}
The 'INCLUDEPATH' includes the headers into your project where as the 'LIBS' adds the library file path. The 'CONFIG()' tells qt if you're running DEBUG mode or RELEASE mode.
This copy pasta is fun because you can also configure a custom wizard and make qt dropdown show you a 'create new sfml c++' project by just editing its profile with this.
Last but not least are the needed .dll files from 'C:\SFML-2.5.1\bin' You can add only the ones you need or all of them if you're lazy. You can do this by copying them into the BUILD folder of your project. (to find the build folder by default its a folder in the same path as your project folder with the name of your project prefixed by 'build-' or 'release-')
Make simple c++ project
Choose QMake build system
in project.pro add 2 lines:
CONFIG += link_pkgconfig
PKGCONFIG += sfml-all