Details about my setup: Using a Qt Mingw64 Build with .lib files for 64-bit machine generated per the FFTW instructions: http://www.fftw.org/install/windows.html using Visual Code 2019. Made sure to download the pre-compiled 64-bit DLLs to generate the .lib files.
This excerpt of the .pro file was generated by Qt Creator's Add Library tool:
win32: LIBS += -L$$PWD/fftw/ -llibfftw3f-3
INCLUDEPATH += $$PWD/fftw
DEPENDPATH += $$PWD/fftw
In .CPP where I want to use FFTW library:
#include <fftw3.h>
What is in $$PWD/fftw:
libfftw3f-3.lib
libfftw3f-3.dll
libfftw3f-3.def
libfftw3f-3.esp
fftw3.h
Other misc. files included in FFTW 3.3.5 Precompiled DLL .zip
Where it fails: When I try to build it I get
"error: undefined reference to `__imp_fftw_malloc'"
and more similar errors based on the methods I'm calling from the FFTW library but fails at build.
Qt Creator auto-completes the methods so it seems to be linking the FFTW library correctly.
Related
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.
I made a Qt application using boost serialization that builds perfectly on MacOS and Linux. Now I'm trying to build it on Windows using MSVC 2010.
I'm using Qt5.5.0 msvc2010, boost 1.55.0 msvc2010 binaries downloaded from sourceforge.
The serialization shared libraries that I have are:
boost_serialization-vc100-1_55.dll
boost_serialization-vc100-1_55.lib
boost_serialization-vc100-gd-1_55.dll
boost_serialization-vc100-gd-1_55.lib
boost_serialization-vc100-mt-1_55.dll
boost_serialization-vc100-mt-1_55.lib
boost_serialization-vc100-mt-gd-1_55.dll
boost_serialization-vc100-mt-gd-1_55.lib
There is no boost_serialization.lib.
In the .pro file I defined the boost macro:
DEFINES += BOOST_ALL_DYN_LINK
and I'm linking the library in this way:
LIBS += -L"$$PWD/../libs/boost-1.55.0/windows/lib" -lboost_serialization
but I still get the error.
I don't know how to solve this problem.
Any idea?
I have a Qt app & a few libraries built using .pro file in each. When building for windows, I want to build my app in debug mode & hence link to debug versions of my libraries. All if this here is static linking. I build the debug versions of my libraries. All fine. pdb files also generated in the build folder.
But when I build my app it complains of the following error appending a D to my library name !!!
error: LNK1104: cannot open file 'MyLibD.lib'
It should be looking for MyLib.lib not MyLibD.lib as I specifying below in MyApp.pro. Following is how I link to my library in MyApp.pro
LIBS += -L$$MyLib_build_location -lMyLib
Release:win32: LIBS += -L$$MyLib_build_location -lMyLib
Debug:win32: LIBS += -L$$MyLib_build_location -lMyLib
INCLUDEPATH += $$MyLib_include_location/
DEPENDPATH += $$MyLib_include_location/
unix:PRE_TARGETDEPS += $$MyLib_build_location/MyLib.a
Release:win32:PRE_TARGETDEPS += $$MyLib_build_location/MyLib.lib
Debug:win32:PRE_TARGETDEPS += $$MyLib_build_location/MyLib.lib
Why is windows OS expecting my library to be appended with D when in debug mode ? How can make Qt look for the same name as TARGET specified in library´s .pro ?
Note that, I am using Visual Studio 2015 Community edition along Qt Creator for the C++ compiler
You're building a debug build of your application: it needs to link with debug libraries! You need to fix the project files for the libraries so that the debug build is available, with the correct prefix.
Also note that the manual tweaking of build locations is usually counterproductive.
I am trying to include ffmpeg in my qt project on windows. I am running QT4 and compiling with microsoft visual compiler 2010 on 32 bit windows 7. I am trying to include ffmpeg 2.8 which I got the dev and shared downloads from zeranoe. When I run it I get the following output:
Starting (executable path)...
The program has unexpectedly finished.
(executable path) exited with code -1073741819
I am able to produce this output with the following:
ffmpeg_test.pro:
QT += core
TARGET = ffmpeg_test
INCLUDEPATH += (ffmpeg dev path)/include
LIBS += -L(ffmpeg dev path)/lib
LIBS += -lavformat
SOURCES += main.cpp
main.cpp:
extern "C"
{
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include <libavformat/avformat.h>
}
int main(int argc, char *argv[])
{
av_register_all();
return 0;
}
I have put the .dll files from the ffmpeg share bin into the same folder that QT builds ffmpeg_test.exe into. I have also confirmed that they are found using dependency walker which shows a question mark when they are not in that directory and the avformat-56.dll file path when they are (the fact that the .dll files are found does not effect the output of the program).
Dependency walker does reveal that something weird is going on as there are no expected functions, but the functions found in avformat-56.dll look correct. I also have ran Dumpbin.exe /EXPORTS on avformat.lib and it also looks fine (I can post output if it would be helpful). It is worth noting that I have included this version of ffmpeg in a different application on this machine, it was not a qt project however. That project generated its make file with CMake rather than QMake and was built with Microsoft Visual C++ 2010 rather than QT Creator.
I have also included other .lib/.dll pairs in qt and they have no problems. I am noticing two differences from those pairs. First in the ffmpeg-dev lib folder instead of having only .lib files (as is the case for all my other .lib/.dll pairs) I also have a .def and a .dll.a file for each library. Second ffmpeg is a c library whereas all my other included libraries are c++.
update 3/29:
I have tried replacing the LIBS lines in my .pro with both of the following:
LIBS += (ffmpeg dev path)/lib/avformat.lib
LIBS += (ffmpeg dev path)/lib/libavformat.dll.a
Both give the same error message. I have also tried adding the following to my .pro file also with no effect.
DEFINES += __STDC_CONSTANT_MACROS
QMAKE_CXX_FLAGS += -D_STDC_CONSTANT_MACROS
Additionally I tried adding #define inline __inline to main.cpp as suggested on the ffmpeg website. Any ideas of things to try would be hugely appreciated!
update 3/31:
I have tried to start over with a new Windows build environment but the result remains unchanged with the test code above. (The new environment was able to run a hello world program).
My process for setting up this environment was to install a fresh version of 32 bit windows 7. Install Visual C++ 2010 Express from the Visual Studio 2010 Express All-in-one ISO. Install Qt 4.8.6 for 32 bit windows and Visual Studio 2010. And finally install Qt Creator 2.5.2. To set up Qt creator I went under tools->options and told it where to find the Qt 4.8.6 qmake. I downloaded the dev and shared builds for ffmpeg 2.8 from Zeranoe. I was missing stdint.h and inttypes so I downloaded them and put the files in /include/libavutil. Then I corrected any of the header files that complained from to "stdint.h" ect. I then put the dll files from ffmpeg-2.8-win32-shared/bin into the folder where qt was building ffmpeg_test ffmpeg_test-build-desktop-Qt_4_8_6__4_8_6__Release/release.
The problem is that ffmpeg was compiled with the MinGW compiler and sometimes libraries compiled with different compilers may not always be compatible. I was able to make my test program run correctly by getting the MinGW compiler and setting up Qt for MinGW. Also my version of ffmpeg did not require the changes involving stdint.h or inttypes.h. How this version of ffmpeg was able to compile using MSVC and cmake is still a mystery to me. For a path forward the question is if switching to the MinGW compiler is a option or if I need to compile ffmpeg for MSVC.
Turns out static linking was working, but only for Qt libraries. My 3rd party library QtSerialPort is not linking statically. After some reasearch, I've found that I either have to build this library statically or I have to link directly to a .pri file in my .pro file.
I'm not sure how to do either since it seems QtSerialPort has not been designed for static linking.
The .pri method I really don't understand and has been vaguely described in these two links:
http://qt-project.org/forums/viewthread/15223
http://www.qtcentre.org/archive/index.php/t-54505.html
Does anyone have any adivce on how to get either of these methods to work? Or possibly another method?
Also, MSVCP100.dll is not linking statically if anyone could give me any advice on that.
==================================================================================
I am trying to get Qt to statically link libraries so that I can make a standalone application. I have followed various tutorials on how to build Qt statically then building a static application but I am not having much luck. I believe I have succesfully built Qt with static linking because the application has grown in size from 79KB to 7+MB but I am still getting errors saying QtCore4.dll and QtSerialPort.dll are missing. Also, another issue I'm having when using this static configuration, which isn't too serious, is that when I close my program Windows thinks it has crashed and gives me a window saying MyProgram.exe has stopped working...
I am on a Windows machine using MSVC 2010 with Qt 4.8.5 and am using the third party library QtSerialPort.
What I've done accoring to the guides I've been reading is:
Download and extract qt-everywhere-opensource-src-4.8.5.zip
Open /mkspec/mwin32-msvc2010/qmake.conf and change the follwing lines to
CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target
and
QMAKE_CLFAGS_RELEASE = -O2 -MT
I then open the MSVC2010 command prompt and cd to this . I then enter the commands
configure -static -release -platform win32-msvc2010
nmake sub-src
After this is done I open my project and add
CONFIG += static
to the .pro file. In QtCreator I then go into Projects, Manage Kits then to Qt Versions and browse to the qMake I just generated. I add a new Kit with this version of qMake. I then clean all and switch to this new kit and run qmake from QtCreator. I then use msvc2010 command prompt to go to the directory where the files are generated and then
nmake release
This generates a rather large .exe but like I said, it's still depending on a couple .dll's.
For static linking of external library one have a couple options, both have their pros and cons.
I. Compile the library for static linking yourself. Link to it.
Look for possible existing configuration switches for static linking. There can be something like QTSERIALPORT_STATIC = no, etc. in the library's .pro/.pri files. Just say yes for the library to compile for static linking and go to the step 4!
In .pro/.pri file replace CONFIG += dll with CONFIG += static.
Remove export declarations from the library. Typically Qt library symbols are declared with some definition like QTSERIALPORT_EXPORT which expands to Q_DECL_EXPORT/Q_DECL_IMPORT in shared library build / its header files usage when linking. You'll need to find where this QTSERIALPORT_EXPORT is defined and replace it with empty definition:
#define QTSERIALPORT_EXPORT // in source file
or
DEFINES += QTSERIALPORT_EXPORT # in .pro/.pri file
Build the library.
Link to the library .lib/.a file, use the library header files for symbol declarations in your project.
II. Include the library source files into your project and compile them within it (no linking at all).
Include all the source files of the library into your project (add to SOURCES in qmake project file)
Determine all the stuff the library depends on (other libraries, Qt options, etc.) and include it also into your .pro file.
OR
Include the proper .pri file into your .pro if the library author provides it for in-project compilation (i.e. include(QtSerialPort.pri) or something.)
Remove export/import declarations from the library source code — as described in the item 3 of part I.
Build your project.