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.
Related
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.
I am using Qt Creator for development. I want to use Armadillo linear algebra library. Therefore I used following code in my pro file:
INCLUDEPATH += C:\armadillo-7.950.1\include
LIBS += \
-LC:\armadillo-7.950.1\examples\lib_win64 \
-llapack_win64_MT \
-lblas_win64_MT
It was all good and the project compiled and linked properly. Next task was to replace LAPACK and BLAS with OpenBLAS. So the pro file was changed as following:
INCLUDEPATH += C:\armadillo-7.950.1\include \
C:\OpenBLAS-v0.2.19-Win64-int32\include
LIBS += \
-LC:\OpenBLAS-v0.2.19-Win64-int32\lib \
-llibopenblas
Now I receive the error: LNK1104: cannot open file 'libopenblas.lib'. I have downloaded windows binary of OpenBLAS. The installed folder structure is as given in the image: installed OpenBLAS folder
Please let me know what is going wrong?
Thanks.
There are two reasons for this problem:
Weird naming of .lib file as libopenblas.dll.a even though package is called windows binary.
Incomplete binary package---- It doesn't contain all required dlls
Solution:
Choose a binary----win 64 or win32 and download it.
rename libopenblas.dll.a as libopenblas.lib as Yuriy has suggested
download from https://sourceforge.net/projects/openblas/files/v0.2.14/ required missing DLLs are bundled again under weirdly named zip files "mingw64_dll" or "mingw32_dll" depending upon the binary type which you have downloaded in step 1. These zip file contain "libgcc_s_seh-1.dll", "libgfortran-3.dll" and "libquadmath-0.dll"
Add include and lib as I have done to your project and build with correct target depending upon your downloaded binary i.e win64 or X86
Copy libopenblas.dll from bin folder of OpenBLAS binary and "libgcc_s_seh-1.dll", "libgfortran-3.dll", "libquadmath-0.dll" from "mingw64_dll" or "mingw32_dll" depending upon the binary type to build debug or release directory where the exe reside.
Run your program and you are good to go.
If you want to escape copying again and again set a required system environment variable for the path containing these DLLs
I'm not familiar with OpenBLAS, but your configuration looks correct.
On Windows, or at least with MSVC, you need a .lib file to link to, in addition to the DLL file for runtime. Instead it looks like OpenBLAS installs a mysterious .dll.a file. Sounds like it should be the same thing:
https://github.com/xianyi/OpenBLAS/wiki/How-to-use-OpenBLAS-in-Microsoft-Visual-Studio
Possibly renaming it would do the trick, but you might need to rebuild from source to get the file.
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.
I need to ship a product with shared libraries (Ubuntu) in a folder I've created ('shared') within the project directory--i.e., shared libraries that are not in /usr/lib, /usr/local/lib, etc. To this end I've done this in the .pro file, i.e.
LIBS += -Lshared/gsl -lgsl -lgsl_cblas
NB the executable is in the same directory asy the 'shared' folder. Everything works when I launch the program in debug mode from QtCreator. In addition the program fails to launch if I remove or rename the libs in 'shared', and also I've verified that the app is not finding these libraries anywhere else. But when I launch from the command line, I get
error while loading shared libraries: libgslcblas.so.0: cannot open
shared object file: No such file or directory
What's going on?
EDIT: The solution is a variation on lionbest's below, as developed in the comments. For some reason, it turns out that on my platform qmake/QMAKE_FLAGS only allows a specific format for linker options, and not the one you find googling around for other instances where people have worked with QMAKE_FLAGS. Namely,
QMAKE_FLAGS += "-Wl,-rpath,\'\$$ORIGIN/shared/gsl\'"
QMAKE_LFLAGS_RPATH=
Specifically, the problem was that the parser (or linker) would not accept -rpath=..., despite the fact that this seems to work for everyone else. Ubuntu 12.04, gcc 4.6.3, Qt 4.8.0, QtCreator 2.4.1 "based on Qt 4.7.4". Hope this experience can save someone else the same frustration.
Start a program with environmental variable LD_LIBRARY_PATH=shared/gsl or add a RPATH to linker settings:
LIBS += -Wl,-rpath=shared/gsl
If you want to make shortcut for your application, most distribution (based on Gnome, KDE, LXDE and XFCE) use a .desktop file. QtCreator probably generated one for you. You need to edit it or generate it, and put to $HOME/.local/applications or /usr/share/applications/ during installation. In desktop file you could add envirometal varible and starting directory as follow:
Exec=/usr/bin/env LD_LIBRARY_PATH=/<path_to_libs>/ /<path>/app -extra_options
If you need to run your application in specific directory add line:
Path=/<path_to_your_application_working_dir>
You can use ${} inside path.
main.cpp which should be executable C++ app. It shall depend on
Lib1 be a required to be compiled first (before main.cpp) project-lib (with lib1.h and lib1.cpp inside some separate folders)
'Lib2.lib' with its dependency given precompiled libs (like cross-platform OpenCV for example)
I need it to work for Windows and Linux and if possible Mac OS
found for windows: look here - "Common tasks" page 26
exe hello : hello.cpp some_library.lib /some_project//library
: <threading>multi
;
I hoped for better - more readable syntax form Boost creators... And BTW
What the hell on earth does
On Windows, if an application uses
shared libraries, and both the
application and the libraries are
built using Boost.Build, it is not
possible to immediately run the
application, because the PATH
environment variable should include
the path to the libraries. It means
you have to either add the paths
manually, or have the build place the
application and the libraries into the
same directory.
mean? I can not have a project with 2 nested project - one for .lib and one for app using that .lib?
With this I see how to connect 1 .lib but how to connect a folder with them? And how to connect includes? And when I'll go to Linux what shall be changed?
How should my bjam make/config file look like?
It sounds like you want a framework which works on a cross-platform(Multiple operating system) scenario.
Simplest option would be to install cygwin and create a standard makefile for linux. Compile in a cygwin environment to generate the windows equivalent.
You will save substantial time in creating the makefile.
Another option is mksnt.