Compiling QT OPCUA on Windows - c++

I have a problem when I try to compile Qt OPCUA on windows with open62541.
I am following this tutorial (Building On Windows - Mingw32)
I cannot seem to specify the path to the header open62541.h and the lib open62541.a even if I did
set QTOPCUA_OPEN62541_INCLUDE_PATH=c:\path\to\open62541\build
set QTOPCUA_OPEN62541_LIB_PATH=c:\path\to\open62541\build\bin
Note that open62541 is compiled and that I do have the files open62541.h and libopen62541.a (in version 0.3) where they should be.
The error I get is a linker problem : cannot find -lopen62541
I added manually the open62541.h to the project files since it was not working either.
What should I do to specify correctly the path to open62541 please ? Is there an up-to-date documentation ?

You need to add the path where libopen62541.a is to the library path directory.
If you are using QMake, you need to specify add it to the LIBS variable prepending the path with a -L as follows:
LIBS += -L$${PATH_WHERE_LIB_FILE_IS}
Take a look on how is done in the QUaServer project.
If you are using CMake, then take a look at this answer on how to add to the library path directory.
What you are doing with those commands is telling the linker where to find the missing libraries.

Related

CMake and MinGW-w64 include paths

I have a C++ project that needs to be built with CMake and MinGW-W64.
Some libraries (such as zlib, libpng) are in: C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32\
So I use : -DCMAKE_PREFIX_PATH="C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32"
But, I get a compilation error because the following header is outdated and miss important symbols:
C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32\include\float.h
If I add a compiler flag to search into the proper include directory for float.h:
-DCMAKE_CXX_FLAGS="-isystem C:/Dev/mingw64-5.3.0/lib/gcc/x86_64-w64-mingw32/5.3.0/include"
Then, this does not work, since CMake will add this folder after its generated includes_CXX.rsp
How can I handle this issue? Is there a way to enforce header search path priority?
You could also add the include location(s) to environment variable C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
To locate the libraries you can do the same for the lib with the LIBRARY_PATH environment variable.
For DLL and EXE files you may even need to add the bin path to PATH.

How to include external libraries in Qt

I want some basic explanation about how external libraries are added to a Qt C++ project in a Linux environment
I've installed a library called podofo in two ways :
- Installed it with apt-get install libpodofo
- Installed the source code and build it
Afterwards i added in the .pro file of my Qt Project : LIBS += -lpodofo
How do i choose whether he works with the first or the second one ?
How am i supposed to add an external library with a lot of .jar files in my project ?
I figured it might be something in the run environment but i still don't get it. I tried changing it but it seemed better to just copy libraries manually in the file Qt is installed in.
Like most libraries on Linux, podofo installs a pkg-config file. The file is named libpodofo-0.pc. qmake has built-in support for that, so all you need to do is add this to your project file:
PKGCONFIG += libpodofo-0
(Note that for this to work, you might need to add link_pkgconfig to your CONFIG line.)
Do not add anything to LIBS. qmake will call pkg-config and add the needed compiler and linker flags automatically. Specifically, it will add the correct -l flags for linking, and the correct -I flag for compiling (usually -I/usr/include/podofo). So when you include the podofo headers in your code, don't use #include <podofo/podofo.h>. Use #include <podofo.h> to keep your code portable when building on systems that might be using a different directory name to install the podofo headers.
Make sure that the pkg-config tool is actually installed on your system though. pkg-config --version should print something like 0.29.1. If instead the command is not found, then install the pkg-config package of your Linux distribution.

How can Codeblocks find my header files even without adding any search paths

I'm learning to use OpenCV (and C++) in Codeblocks. What confuses me, however, is that when I start to include header files from OpenCV in my main.cpp file, Codeblocks automatically suggests to me the files as shown in the image below.
I have not included any search paths to project build options, so how is this possible that Codeblocks can find the files? Is there some other variable working here that I'm unaware of?
Note that I'm a beginner with both Codeblocks and OpenCV and that I only have a little experience with C++.
Thank you
Of course when you install an IDE like code::blocks by default, it knows about standard path for library on your OS.
On my OS -> Ubuntu that is /usr/include
It only searches on a standard path, except you add one. If you install your library by command-line, it goes to the standard place, if you installed manually, then it depends on your option you added to installation. I can not see you screen-shot but it has access to /usr/include by default.
For more detail on Linux and OpenCV
And here is a screen-shot of codeblock on Ubuntu that I added some 3rd-party library
NOTE:
if you install any libraries by command-line, just use it.
But if you have installed them manually, you need to add 2 things to codeblock.
1. First is your path for header file
2. Second is your path for linker
And you see it in screen-shot that say: Search Directory
First is for header and second is for linker

dns_sd.h no such file or directory windows qt

I want to use the equivalent linux library libdns_sd.so on Windows.
I'm using QT/C++ to build an application using dns_sd.h
I'm facing an error, I have :
dns_sd.h: No such file or directory
On Linux, it works perfectly with this line on my .pro file :
LIBS += /usr/lib/x86_64-linux-gnu/libdns_sd.so
I don't know what to include on Windows to make it working.
I downloaded the mDNSResponder on https://opensource.apple.com/tarballs/mDNSResponder/ but I don't find the library to include.
Thank you !
The LIBS variable causes you to link to the libdns_sd.so shared library, this isn't related to the problem you are seeing. The compiler isn't complaining about a missing shared library, it is complaining about a missing header file, dns_sh.h.
On all platforms, header files have to be found in the include path. Typically on Linux when you install a dev package, the header file is placed in one of the commonly used include paths.
On Windows you'll need to configure the include path yourself. Use the INCLUDEPATH variable in qmake. Add the path to dns_sd.h on your Windows system and the program should compile... make sure to also link to the dll.

How do I remove the library paths that qmake automatically adds to the linker options

Wanted to try using qt creator (coming from eclipse cdt) and I'm trying to get my project to build. Unfortunately, qmake is adding -L/usr/lib to the linker options by itself, making it link to the wrong version of a library, and I can't figure out how to remove it.
I've tried doing "LIBS = " in the project file, as well as "LIBS -= -L/usr/lib", but it seems to be adding the option after it reads the settings from the project file. Anyone know if there's a conf file somewhere (e.g. mkspecs directory) where I can comment this out? Thanks.
It comes from qmake itself. It puts qt_libspath into link flags. It can be changed by either configuring and compiling Qt with a different directory prefix, or by modifying the qmake binary itself.
An easy solution for you could be to create a filesystem-level link to the correct library version with a different name. That is, if you have /usr/lib/libfoo.so and myfoo/lib/libfoo.so, create a link libmyfoo.so -> myfoo/lib/libfoo.so and link with -lmyfoo instead of -lfoo.