Linking a lib file with a non-standard name in Qt - c++

On Windows, I'm attempting to add an external DLL to my Qt project (via Qt Creator). I have the following generated artifacts I'm trying to reference:
target/debug/mylib.d
target/debug/mylib.dll
target/debug/mylib.dll.d
target/debug/mylib.dll.lib
Adding the library/dll generates the following entry in my .pro file:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/target/release/ -lmylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/target/debug/ -lmylib.dll
INCLUDEPATH += $$PWD/target/debug
DEPENDPATH += $$PWD/target/debug
Qt is expecting "mylib.dll.lib" to be named "mylib.lib", so with the above configuration the build fails with the error:
error: LNK1104: cannot open file 'mylib.lib'
The build works correctly if I rename "mylib.dll.lib" to "mylib.lib", but I'd rather not introduce this extra step, if possible. The dll.lib suffix is generated by Rust/Cargo, and there aren't any plans to allow this to be configured.
After doing some research, I've tried a couple of different options, including referencing it in PRE_TARGETDEPS, but I can't make the LNK1104 error disappear. What am I missing?

I figured it out. The trick is to refer to the files directly (i.e. not using the -L / -l parameters), like this:
win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll.lib
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll.lib
win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll

Related

CGAL Linking Error QT Creator Project for Windows and Linux

I have problems creating a project using QT with CGAL and Boost on Windows 10.
In this project there are a few .pro Files and all projects without CGAL have compiled. Boost also works without problems. If I compile the CGAL Project i get linking errors:
Link Errors
Here is my .pro file
win32:INCLUDEPATH += C:/CGAL32/include/
win32:INCLUDEPATH += C:/CGAL32/build/include/
win32:INCLUDEPATH += C:/boost_lib_inc/include/
win32:INCLUDEPATH += C:/boost/boost_1_68_0/
win32:CONFIG(release, debug|release): LIBS += -LC:/CGAL32/auxiliary/gmp/lib -lgmp-10 -lmpfr-4 -LC:/CGAL32/build/lib/Release -lCGAL-vc140-mt-4.12.1 -lCGAL_Core-vc140-mt-4.12.1
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/CGAL32/auxiliary/gmp/lib -lgmp-10 -lmpfr-4 -LC:/CGAL32/build/lib/Debug -lCGAL-vc140-mt-gd-4.12.1 -lCGAL_Core-vc140-mt-gd-4.12.1
else:unix:!macx: LIBS += -L$$PWD/../../../../../../usr/lib/x86_64-linux-gnu/ -lCGAL
On Linux all works fine.

C++ HDF5 cannot find -lhdf5d

Situation: I want to create a program to read something from a .hdf5 file.
What i did: Nothing, but adding the hdf5.lib to the project.
Problem:
I get two Errors
when i try to run the program.
cannot find -lhdf5d
error: ld returned 1 exit status
My Code:
HDF5_Test.pro:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5d
else:unix: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
main.cpp:
#define H5_SIZEOF_SSIZE_T H5_SIZEOF_LONG_LONG //this is needed to avoid redefinition conflict of ssize_t (Qt vs HDF5)
#include <hdf5.h>
#include <H5Cpp.h> //Tried with and without this include
int main()
{
return 0;
}
Using:
C++
Qt 5.10.1
MinGW 32bit
HDF5 1.10.2
Windows 7
In another project for whatever reason these Errors doesn't occur, but these.
.
I linux, using apt-get install libhdf5-dev we get 8 libs installed but none is lihdf5 in its "nature". What i mean by that is that my include would be -lhdf5_openmpi and not-lhdf5. as you didn't provide the download source, try to check if you have multiple libs in your /lib file
The Solution was for me to delete the final "d" in this line:
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5d
Meaning i changed -lhdf5d to -lhdf5.
This problem was fixed this way but lead to another problem.

How to correctly link your own library to your project in Qt on Windows?

In my QtCreator C++ project I'm using subdirs template and have several subprojects including lib-project. In app-project I'm trying this:
win32:CONFIG(release, debug|release): LIBS += -L../Library/release -lLibrary
else:win32:CONFIG(debug, debug|release): LIBS += -L../Library/debug -lLibrary
else:unix: LIBS += -L../Library -lLibrary
On Linux it works well, but on Windows library compiles (there're .dll and .a files), linker links it (if I change the path to wrong, like -L../Library/debugg I have an error - can't find -lLibrary), but then I have "undefined reference to [my_classes]". INCLUDEPATH and DEPENDPATH are also correct (because it works on Linux):
INCLUDEPATH += $$PWD/.. $$PWD/../Library
DEPENDPATH += $$PWD/.. $$PWD/../Library
Also tried this:
LIBS += -L$$OUT_PWD/../Library/release -lLibrary
Same result, so what should I do?

/usr/include/libfreenect.hpp:33: error: libusb.h: No such file or directory

I installed libfreenect. I opened QT and began to coding. When I use libfreenect.h no error occurres. But when I use libfreenect.hpp, this error occurred:"error: libusb.h: No such file or directory"
contents of .pro file is:
QT += core
QT -= gui
CONFIG += c++11
TARGET = 12moharram
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../usr/local/lib/release/ -lfreenect
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../usr/local/lib/debug/ -lfreenect
else:unix: LIBS += -L$$PWD/../../../usr/local/lib/ -lfreenect
INCLUDEPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/include
Where is the problem?
Probably libfreenect.h and libfreenect.hpp are themselves including other files, for a reason that I cannot understand libfreenect.hpp is including libusb.h and libfreenect.h is not. Probably libusb.h is not in your INCLUDEPATH.
I would first try to find libusb.h, if it is not present install it (you will probably have to install libusb-dev (debian style). Once you are sure libsub.h is present make sure is in the INCLUDEPATH, in case change the INCLUDEPATH in your .pro file.
This should fix this specific problem but after you fix this there can be more, good luck.

"No rule to make target" error when adding an external library in Qt Creator

I am new in the world of Qt. I would like to add an external library of wxMSW-2.8.12 in Qt Creator. In order to do that, I right-clicked on my .pro file and clicked on "Add Library", then I select "External Library". I finally choose the Library file, click on "Static" for "Linkage".
This is what I got automatically from Qt Creator:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/ -lwxbase28ud_xml
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/ -lwxbase28ud_xmld
else:unix: LIBS += -L$$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/ -lwxbase28ud_xml
INCLUDEPATH += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib DEPENDPATH += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xml.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xmld.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/wxbase28ud_xml.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/wxbase28ud_xmld.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xml.a
But, when running, I get this error:
:-1: erreur : No rule to make target 'C:/Qt/Qt5.2.0/Tools/QtCreator/bin/testConverter/../../../../../../wxMSW-2.8.12/lib/vc_lib/libwxbase28ud_xmld.a', needed by 'debug\testConverter.exe'. Stop.
I tried to clean and rerun qmake but with any success.
Any suggestions?