C++ HDF5 cannot find -lhdf5d - c++

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.

Related

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

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

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.

Adding jsoncpp external library to my qt project : (symbol(s) not found for architecture x86_64)

I'm trying to add jasoncpp library to my C++ qt project.
I included the header, and linked (I think) the library but I get these errors:
"symbol(s) not found for architecture x86_64" and "linker command failed with exit code 1 (use -v to see invocation)".
The symbols not found are obviously the ones concerning jsoncpp library.
This is my makefile:
QT += core gui webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = JsonTest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/release/ -ljson
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/debug/ -ljson
else:unix: LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/ -ljson
INCLUDEPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
DEPENDPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
I really don't know how to proceed so thanks in advance.
If you installed it using cmake, try this commands:
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../..
make
change
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/release/ -ljson
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/debug/ -ljson
else:unix: LIBS += -L$$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/lib/ -ljson
INCLUDEPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
DEPENDPATH += $$PWD/../../../../../../../usr/local/Cellar/jsoncpp/0.5.0/include
for this:
unix|win32: LIBS += -ljsoncpp
and ready to use jsoncpp

"cannot find -lQt5Core -lQt5Gui etc" when using other not related libraries

ISSUE SOLVED (scroll down)
Im on windows 7 and compilling with MinGW.
I made a new Qt application in QtCreator 3.01 (Qt 5.2.1). I compile it, the empty application window pops up everything is awesome. But as soon as i use any other library (like boost or gtest) im starting getting these errors when compiling
cannot find -lqtmain
cannot find -lQt5Widgets
cannot find -lQt5Gui
cannot find -lQt5Core
ld returned 1 exit status
This is my .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2014-04-19T14:17:24
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Thermovision
TEMPLATE = app
include(Model/Model.pri)
include(Controller/Controller.pri)
include(View/View.pri)
include(Interface/Interface.pri)
SOURCES += \
main.cpp
HEADERS += \
logdebug.h
FORMS +=
OTHER_FILES += \
Model/Model.pri \
View/View.pri \
Controller/Controller.pri \
Interface/Interface.pri \
Globals/zGlobals.pri
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
INCLUDEPATH += $$PWD/../../../../../../../MinGW/msys/1.0/local/include
DEPENDPATH += $$PWD/../../../../../../../MinGW/msys/1.0/local/include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../Downloads/boost_1_54_0/boost_1_54_0/stage/lib/ -lboost_thread-mgw48-mt-1_54
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../Downloads/boost_1_54_0/boost_1_54_0/stage/lib/ -lboost_thread-mgw48-mt-1_54d
this is the main.cpp
#include <iostream>
#include <QApplication>
#include "View/form.h"
#include <boost/thread.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Form w;
w.show();
boost::thread b;
return a.exec();
}
when i comment usage of boost thread, the include and the part in .pro file responsible for finding boost thread library everything compiles again. Same when im trying to use gtest.
The odd thing is that I havent found any information regarding this issue anywhere on the internet :<
Can someone help me?
=================================================================================
[SOLVED]
ok so it seems qt wanted me to explicitly add the libraries into project. I used the built-in tool which generated the following output
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Cored.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Cored.lib
but im sure one can thin it down (im gonna stay with this)
Based on our comments and outcome, it seems that a quick solution is to add the libraries explicitly that you wish to use. It will generate something like this in the background, so basically using static libraries as opposed to dynamic:
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/libQt5Cored.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/Qt5Cored.lib
Alternatively, which I would personally suggest more is to add the following line for now in your project file to get this working with dynamic libraries rather than static to make your application binary go up to the hill:
LIBS += -L$$PWD/../../../../../../../Qt/Qt5.2.1/5.2.1/mingw48_32/lib/