Qt (Creator) with WinSocks (ws2_32) - c++

I want to use an older code-fragment in my Qt-project, which is using WinSocks.
I created my program with Qt Creator and I don't know, how I can link to the ws2_32-Library. I already added LIBS += -lws2_32 to my .pro, but nothing happened. So how can I link to this library?
edit: Where can I find the ws2_32.lib to include it? Do I have to download it first? I know it comes with "Visual Studio", but I don't use it and I don't want to use it.

ok, when you know it, it's really simple.The Qt-SDK comes with a WinSock2-Library, called libws2_32.a.The only thing you have to
do, is to enter this line in your .pro:
LIBS += C:\Qt\2009.04\mingw\lib\libws2_32.a
this includes the winsock2-library to your project and you have nothing else to do.
You may do this slightly more simply by using this line in your .pro:
LIBS += -lws2_32

You are supposed to use the full or relative path (depends on what library paths you have in your enviroment) to the .libs.
From the qmake manual:
win32:LIBS += c:/mylibs/math.lib

You need too to add the path to the headers in order to add the function's signatures of a dynamic library.
Use the INCLUDEPATH variable into the .pro file.

I have ws2_32.lib in c:\Program Files\Microsoft SDK\Lib\WS2_32.Lib it comes with the platform sdk. I have a very old version from Feb 2003 I think, I only needed it when I was using VC6.0, but I assume it is in the latest version too.

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.

Update translation file using Boost library Qt C++

I am using the Boost library in my C++ project.
I am including it in the PRO file like this:
win32: INCLUDEPATH += C:/boost_1_60_0
win32: LIBS += "-LC:/boost_1_60_0/stage/lib/"
But, when I run the following command on the terminal (cmd) to update my translation file:
lupdate MyProject.pro
It searchs for files in the Boost library path to update.
Is this normal? What can I do to not search in the Boost library path?
Now, I am commenting the Boost include lines when I need to run the lupdate command, but I don't want to do it every time I need to update my translation file.
Qt 5.3.2
Boost 1.6.0
There is a workaround in the bug report (QTBUG-27936), involving the TR_EXCLUDE option in the .pro project. It is used to tell lupdate to exclude certain files. I tested with Qt 5.6 and 5.8 and it worked as expected. Here there is the extract of my .pro file:
INCLUDEPATH += /Users/user/libs/boost
TR_EXCLUDE += /Users/user/libs/boost/*
PREVIOUS ANSWER
This is the previous answer, which I couldn't confirm and it happens to be wrong. I'm letting it here so it's kept documented. There is a workaround in the bug report (QTBUG-27936), which is to include all Boost libraries in the precompiled header, since lupdate doesn't look at it.

Error compiling C++ program against GeoIP library

I'm trying to compile a simple program using the GeoIP2 lite API. I've compiled the GeoIP Lite program and it created the library files. The .la file is in /mydir/libmaxminddb-0.5.3/src
I modified my .pro file to include:
LIBS += /mydir/libmaxminddb-0.5.3 -lmaxminddb
but when I compile my project errors with "Cannot find -lmaxminddb"
Can someone tell me what's wrong? I've tried changing directories, adding a "lib" prefix to the maxminddb, and more, but I can't figure it out.
(I'm trying to link against libmaxminddb.a which is pointed to by libmaxminddb.la)
I believe in autoconf and friends the -l flags go in the LDFLAGS variabe, not LIBS.
I found elsewhere that with Qt Creator you can right click the project and add an external library. When I do so, I see the .pro file adds:
LIBS
INCLUDEPATH
DEPENDPATH
So that's what you need to add!
That should be LIBS += -L/mydir/libmaxminddb-0.5.3 -lmaxminddb. Note the extra -L in front of the directory name.

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

How to Link Imagemagick library to Qt(windows)

I have developed an application with mac and for one month now, Im trying to link Qt with ImageMagick on windows.
I just cant find the files and the version of Imagemagick library that need to be linked to Qt in order to make my application work on windows.
I have tried most of the libraries from here
Thats the only thing I added to the .pro file while I was developing on a mac
INCLUDEPATH += . /opt/local/include/ImageMagick
LIBS += -L/opt/local/lib -lMagick++
When I add this to my .pro
INCLUDEPATH += C:/im6/include/ImageMagick
LIBS += C:/im6/lib/libMagickWand.a
LIBS += C:/im6/lib/libMagick++.a
LIBS += C:/im6/lib/libMagickCore.a
C:/im6/lib/libMagick++.a
I get 10.000 + simmilar errors to that:
(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `__gxx_personality_sj0'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `_Unwind_SjLj_Register'
C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4178: undefined reference to `_Unwind_SjLj_Unregister'
For more errors check this
Has anyone tried to build and deploy an ImageMagick application using qt on windows ?
Which files do I need to link while building and which files while deploying ?
The error message tells me that you
use mingw (with qtcreator). Your
library might not work with this
compiler. You need a mingw version
of the library, probably named
libmagick.a.
LIBS += -L$$quote(c:/Program Files/ImageMagick-6.6.5-Q16/lib) -lmagick
(see the documentation about qmake Project Files
I have found that the minGW tool set is very much treated as a "stepchild" in the Windows world. I know it doesn't help your particular situation, but we had numerous problems with third-party libs while trying to use Qt with minGW. There were always extra steps, or non-existent build instructions that we had to figure out or tweak.
Once we switched to the MSVC version, all of those problems went away. Note that this doesn't mean you have to use Visual Studio (you can still use Qt creator), it just means that the Visual Studio compiler is being used. You can get the compiler for free using the Platform SDK. If this is an option, you might save yourself a lot of pain by switching now. It's unfortunate, but that is just the current status quo, at least as we discovered.
Please go get ImageMagick source package.
I can’t give direct instructions how to work with MinGW of Qt Creator, but basically following. I prefer to use qtvars.bat that comes with binary distributions of Qt to set environment.
Open Windows cmd
Set PATH to have /path/to/mingw/bin and /path/to/qt/bin before other paths
Go to directory where you have extracted ImageMagick source
read README, INSTALL and such to compile the ImageMagick (most likely just ./configure ; mingw32-make, but never be sure)
Edit your .pro file with something like LIBS += -L$$quote(/path/to/imagemagick/lib/dir) -lmagick . The lib may be in bin dir or in lib dir. See hmuelner’s answer for more information.
At this point, the configuration should be ready. Compilation at Qt Creator should work, but you can as well use this cmd windows to compile your program: go to program directory, run “qmake” and “mingw32-make”.
You cannot link against a ImageMagick++ library built with MSVC, as mingw and MSVC DLLs are incompatible for C++ libraries. You can't link a MSVC-built C++ library into a mingw project, nor vice versa. C-only libraries work fine. Also, according to this fortum thread, using builds against old mingw-versions with current mingw versions doesn't work as the exception handling changed (as you get more errors than that, I wouldn't expect that to be the only problem though). If there is no binary package for your mingw version (and I don't see any on the imagemagick website), your only option is to use a source package, as Smar suggests.
Another option of course is to install Visual Studio, download Qt for MSVC and build your project with MSVC.