Using STXXL in Qt project - c++

How do I get qmake to include the stxxl.mk file into the generated makefiles?
I have a Qt project, which deals with large files (>RAM) and therefore want to employ STXXL. The STXXL documentation says:
Building an Application
After compiling the library, some Makefile variables are written to stxxl.mk [...] in your
STXXL_ROOT directory. This file should be included from your application's Makefile.
Of course I can edit the makefile by hand to add the line include /path/to/stxxl.mk but it is very tedious to do this everytime the .pro file and hence the makefiles change.
I already searched for some solutions with qmake commands in the .pro file, but to no avail. In one forum they suggested to edit the qmake source and recompile it, but this is no choice if the program will be distributed to others, who do not have this "fix" in their qmake.
Maybe I am thinking to complicated and there is a simple solution. I hope there are some people here who did solve this problem, when working with this combination (Qt + STXXL).
Note
This question Prepend/Append Makefile to a Qt generated Makefile was asking for quite the same but the solution does not fit to my problem.

For now I have settled with the following solution:
As the stxxl.mk file contains "valid qmake code" (it assigns to variables), I use include(stxxl.mk) to import these variables. So my resulting project file contains:
include(/path/to/stxxl.mk)
QMAKE_CXXFLAGS += $$STXXL_CPPFLAGS_STXXL
LIBS += $$STXXL_LDLIBS_STXXL
These were the only variables of stxxl.mk that were used in the documentation so I used them and it works.

Related

How can I help Intellisense find include paths based on CMake variables?

I'm trying to use Android NDK in my project, for which I'm using Visual Studio Code. This means I have a CMakeLists.txt file that uses a ANDROID_NDK variable in order to find both include and source files, and building works. However, Intellisense is not working, meaning that coding is a real pain since it can't recognize includes. I tried using CMAKE_EXPORT_COMPILE_COMMANDS but it just won't work as intended. Should I just manually edit vscode's includePath and expect everyone I share my code with to do the same? Whatever the solution may be, I'd rather have CMakeLists.txt modified so it can help any IDE/editor, but vscode-specific solutions are ok if there's no other way.
I tried set(CMAKE_EXPORT_COMPILE_COMMANDS ON) and editing the appropriate vscode variable for compile commands path but it just won't help.

Qt-Based C++ Project Works If Run From cmd.exe But Not From Within Qt Creator

I am writing a very minimal C/C++ Qt-based application for Windows (only Windows -- not cross platform at all) that uses a VISA library (visa64.dll) to talk to some external hardware. That library, in turn, uses some other libraries:
(screenshot from Dependency Walker a.k.a. depends.exe)
Originally I wrote it in Visual Studio and it worked great. Then I ported it to Qt Creator (using Qt5, w/ MSVC 2015 Visual C++ toolchain) and I got runtime errors. It knows where to find the external header files, so I think my INCLUDEPATH is right, and it builds fine so I think the LIBS variables in my .pro file are right, which is to say it can find the .lib files it needs. However, the first API I call from this external library (viOpenDefaultRM) returns the following error: VI_ERROR_LIBRARY_NFOUND. This happens whether I make a debug build or a release build, and whether or not I am running it with a debugger. As long as I run the program from within Qt Creator, it gets runtime errors.
Here is my .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += $$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Include'
LIBS += -L$$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Lib_x64/msc/' -lvisa64
INCLUDEPATH += $$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Include'
DEPENDPATH += $$PWD/'../../../../Program Files/IVI Foundation/VISA/Win64/Include'
The paths that end with /Include have header (.h) files (it's a C library), and the path that ends with /msc has a .lib file. The .lib files are not static libraries, they are the interface files for some corresponding DLLs. Those DLL files are in C:\System32. There are also 32-bit versions in C:\SysWOW64. They may also exist elsewhere but if they do I am not aware of it.
Now, if I run it from cmd.exe it works fine. That is, if I open a cmd.exe terminal window and navigate to my Qt project's build directory (c:\blah\blah\blah\obj\debug\) and run the executable from cmd.exe, I get no runtime errors. It can connect to the external hardware, talk to it, all good things are happening, much rejoicing.
I've done a decent amount of searching and researching about this problem, and I am somewhat cursed by the fact that most people have the opposite problem, which means that problem (the opposite one of mine) is what turns up in Google/DuckDuckGo/StackOverflow/forum.qt.io/doc.qt.io searches. That problem usually has to do with missing/misplaced Qt libraries. Here is an example. The answer to this question usually ends up with a link to a page on how to deploy Qt projects for Windows, e.g. this article.
Also I've read this article from Qt on how to add libraries to your project, and it didn't help me out, but I could be missing something and/or doing it wrong.
This might be something really dumb I'm missing and frankly I hope it is. Thanks*10^6.
TL;DR: The kit I was using to compile in Qt Creator had a different PATH set than my system PATH. To fix this, I did echo %PATH in cmd.exe and copied all the stuff that had to do with the drivers I'm trying to use into the PATH for the kit I'm using in Qt Creator. More details below.
I got this to work this morning. As suggested by #adrien-lerevat, when run from within Qt Creator, my executable couldn't find some DLLs it needed. The long and short of it is that I was defining a PATH in my kit (a "kit" in Qt is basically a compiler, a debugger, and some environment variables) that was different from, and not a superset of, my normal system path. I had inherited this kit for other purposes, you see, from other projects, and I didn't realize a PATH could be set in it, or that I was setting one. So to find the PATH I was setting for Qt Creator, I went to the Tools dropdown and selected Options..., then Build & Run, then Kits. Then click on the kit you are using to edit it. As such:
That should give you a list of stuff, one thing of which is called Environment. That should have a Change... button you can press:
which should open a new window with all your environment stuff:
(screenshot is from after I fixed the problem)
This is where I found PATH, as well as some library and include paths that were worth knowing about. So now that I knew what my Qt Creator PATH was, I opened cmd.exe and typed the command echo %PATH% to find out what my system PATH was. I grabbed everything that had to do with these VISA drivers I'm using (basically anything with VISA and/or IVI Foundation in the path) and pasted them into my PATH in Qt Creator. This was the list of stuff I pasted in there to make it work:
C:\WINDOWS\system32;C:\Program Files\IVI Foundation\VISA\Win64\ktvisa;C:\Program Files\IVI Foundation\VISA\Win64\bin;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\bin;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\winnt\agvisa;C:\Program Files\Keysight\IO Libraries Suite\bin;C:\Program Files (x86)\Keysight\IO Libraries Suite\bin;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\ktvisa;C:\Program Files (x86)\IVI Foundation\IVI\bin;C:\Program Files\IVI Foundation\IVI\bin;
I added c:\system32 because I know that's where visa64.dll is, which is at least one top-level DLL I know I need. Oddly enough, though, when I added just c:\system32 without all the VISA and IVI Foundation stuff, that didn't work. So, I don't know if everything I added to my Qt Creator path was necessary, as I've just come upon this solution, but once I pare down the list to find out what all I actually needed I will add that information here. Just in case anyone else ever comes across this problem or is curious. And for the sake of completeness I suppose. Okay thanks everyone ;)

How to compile staticly a Qt 5 application?

I would like to compile staticly my Qt 5 application. I used this link :
Qt static linking and deployment
The problem is that I don't know where is the "configure" file or how to generate it ?
ps: the old option to add "CONFIG = static" in the .pro file doesn't work with Qt5
You have to first compile the whole Qt library statically. Then, use that configuration in your projects. Then, your application will be statically compiled.
Qt (when using qmake) takes the compilation configuration from its qmakespec, which is defined during compilation of the Qt library. This includes all the parameters that are used by default.
Keep in mind that this has a learning curve. You have to try and fail a few times. It'll cost you some time to get this right. That link I provided should make this effort easier.
The problem is that I don't know where is the "configure" file or how to generate it ?
QMake make use of several type of files:
.pro
.pri
.prf
The most common is the .pro used for pro-jects. You can find/create it at the root of your project directory.
Creating a QtCreator project will automatically generate one. Be aware that there is also the qbs alternative.
the old option to add "CONFIG = static" in the .pro file doesn't work with Qt5
CONFIG *= static still works, are you sure about any other issue somewhere else?
CONFIG = static will override any previous value, using the * will append the new value without deleting previous configurations. I suggest you to use 'message( $$CONFIG)' to ensure the content is correct.

Can a project created with qmake be compiled without using qmake?

I have some source code that was built with qmake. Compiling it is supposed to be done with qmake qmakefile.pro.
I'd like to compile it without using qmake. Is that even possible? What would the steps be?
Edit: Here's the .pro file.
Yes, you can compile files without qmake.
You need to get any specific compiler settings from qmake and convert them to the other compiler as necessary.
Or you can convert the contents of the qmake.pro file into a makefile or your IDE's project settings.
If the qmake.pro is not a human readable text file, you will have to launch qmake and retrieve the settings. Otherwise search for a conversion tool.
While it is technically possible to translate the .pro file into something else, I would not advise it.
Why?
QMake does a lot of work behind the scenes.
In the case of the .pro file you referenced (http://pastebin.com/viv204Fv), QMake is invoking meta-tools (uic, moc) to create the code for the UI and adding build rules to compile it. You will need to manually code those in your build script.
-. QMake also solves issues of choosing the right compiler and linker options (including the right include files). You will need to determine them yourself and add them to your build script.
The project is already using Qt, so why not use Qt's build script generating tool, QMake? If you have installed a Qt development environment, you should already have qmake installed.

Configuring Qt Creator with executable and DLL project

I am new to QT Creator coming from Visual Studio. I have a session with two projects in it. One is a DLL with some classes that I intend to use for other purposes. The other is an executable console app that uses some of the classes from the DLL.
I currently have these two projects side by side in QT Creator. I can include the header files from the DLL in my EXE project using relative paths "../MyPrject/header.h". But how do I get QT Creator to link and then copy the DLL into the executable debug folder for debugging.
Am I doing this all wrong? Is there a better way? If it includes adding code to the .pro file, please include a link so that I can learn more.
You should make some dependencies between this projects.
opening both projects - you have done.
on editor view, right click on exe-project and select add library...
follow creator hints to add it.
2nd option: you can make subprojects. follow QtCreator: Creating Projects from documentation (help view in Qt Creator)
GwyenBleidD provided a good starting point for including DLLs.
I however, have made a habit out of modifying the .pro file directly here and honestly I prefer to modify the .pro file in the event that something goes haywire.
Suppose I wanted to use the winsock DLL.
In the .pro file, I'd first specify the .dll's corresponding .lib file:
# WinSock2 library (ws2_32.lib file)
LIBS += -lws2_32
# Path to the WinSock2 library
LIBS += -L"c:/mylibraries/"
Additionally, you'll need to specify the include path to the header files here:
INCLUDEPATH += "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/INCLUDE"
Thirdly, in my code I'd have to make sure to include the headers for it:
// I ASSUME it'll be found under something like the
// Visual Studio/VC/INCLUDE directory mentioned above.
#include <winsock2.h>
Lastly, you need to ensure that your application can find the .dll file, typically pointed to using the %PATH% environment variable.
With regards to your setup, I'd make sure that your sub-projects are configured so that the library compiles FIRST (obviously). And then ensure that the LIBS variable in your .Pro project points correctly to your .lib destination according to the build configuration (debug|release).
Qt's PRO (qmake) isn't as terrible as some make it out to be. Just give it a solid half-hour to an hour and you'll get the hang of it. I assume though that you have a solid understanding of libs and DLLs and what not.
http://qt-project.org/doc/qt-5.0/qtdoc/qmake-manual.html
The right way is to switch on CMake based project and keep exe and dll within one root project. The main benefit of this decision is IDE independent approach: you can use Qt Creator, CLion, Visual Studio without any changes in project definition. As the start point consider to see the example project https://github.com/anatoly-spb/cmake_exe_dll