Failed to link openssl to Qt - c++

I have started a project with Qtcreator on linux. This project uses the Openssl library to work.
So In my .pro file I have added theses lines :
LIBS += -lssl
LIBS += -lcrypto
So on linux it works perfectly.
But, I have to continue my project on windows. I had to install Openssl with cygwin, I have chosen this package : "cygwin32-openssl-1.0.1e-1.tar.bz2" because I compile in 32bits.
I have created a sub-repertory, named libs, in my program folder and I put the three openssl folders (bin, include and lib) in my "libs" repertory.
The content of the lib directory is :
libcrypto.a
libcrypto.dll.a
libssl.a
libssl.dll.a
pkgconfig/libcrypto.pc
pkgconfig/libssl.pc
pkgconfig/openssl.pc
In the bin directory I have 2 .dll, cygcrypto-1.0.0.dll and cygssl-1.0.0.dll
I added in my .pro file these lines :
LIBS += -lssl
LIBS += -lcrypto
LIBS += -L"$$PWD/libs/openssl/lib/"
INCLUDEPATH += $$PWD/libs/openssl/include/
If I change -L"$$PWD/libs/openssl/lib/" by -L"$$PWD/libs/openssl/bin/", the compilator don't recognized the -lssl and -lcrypto options.
QtCreator recognized the headers files (for example ) and when I compile, no error occurred.
But when I launch my program, it doesn't work and no error appears.
So I put a breaking point at the begining of my main function, and I re-launch the program. After that a little window indicates to me this error :
Executable failed: During startup program exited with code 0xc0000135
I use Qt 5.4.0 and Mingw 32bits
I don't undertsand why it doesn't work. Can you help me please ?
Thank you.

The entirety of your project needs to use cygwin, or none of it. Since I assume you're compiling using a Visual Studio compiler, you'll need to use an OpenSSL build that isn't cygwin-dependent. For example, the one from Shining Light Productions, the de-fact OpenSSL binary purveyor for Windows.

Related

"Fatal Error C1083: Cannot open include file" in QtCreator

So I am working on a C++ Project in QtCreator which worked fine all the time. The project includes some external libraries for instance DDS solutions, but also it includes a library called "SimConnect". I worked with the library before and everything worked fine, but out of nowhere I am suddenly not able to compile my project anymore.
I am using Qt5.6.0 with a MSVC13 32bit compiler.
C:\dev\simNET\application\P3DHook.h:13: Fehler: C1083: Cannot open include file: 'SimConnect.h': No such file or directory
I know this is a compiler problem, so I rechecked the .pro file to see if it adds the include and lib paths to that library correctly. In my eyes this looks fine (yes the SimConnect.h file actually is in the specified path, I also tried giving it an absolute path but that did not solve the problem either):
win32: LIBS += -L$$PWD/'../../_programme/P3Dv3_SDK/Utilities/SimConnect SDK/lib/' -lSimConnect
INCLUDEPATH += $$PWD/'../../_programme/P3Dv3_SDK/Utilities/SimConnect SDK/Inc'
DEPENDPATH += $$PWD/'../../_programme/P3Dv3_SDK/Utilities/SimConnect SDK/Inc'
win32:!win32-g++: PRE_TARGETDEPS += $$PWD/'../../_programme/P3Dv3_SDK/Utilities/SimConnect SDK/lib/SimConnect.lib'
else:win32-g++: PRE_TARGETDEPS += $$PWD/'../../_programme/P3Dv3_SDK/Utilities/SimConnect SDK/lib/libSimConnect.a'
I also tried to manually re-run qmake and I deleted the whole build folder, cleaned the project and tried to rebuild it. Same error.
So next I took a look into the compile console, and spotted the part where the error occurs:
DNDEBUG -I..\..\..\simNET\plugins\CreatorPlugin -I. -I..\..\..\simNET\application -I..\..\..\_programme\FastRTPS1.5\include -I..\..\..\..\Qt\5.6\msvc2013\include -I..\..\..\..\Qt\5.6\msvc2013\include\QtWidgets -I..\..\..\..\Qt\5.6\msvc2013\include\QtGui -I..\..\..\..\Qt\5.6\msvc2013\include\QtANGLE -I..\..\..\..\Qt\5.6\msvc2013\include\QtCore -Irelease -I..\..\..\..\Qt\5.6\msvc2013\mkspecs\win32-msvc2013 -Forelease\ #C:\Users\crolk\AppData\Local\Temp\CreatorPluginPublisher.obj.2256.47.jom
CreatorPluginPublisher.cpp
C:\Qt\5.6\msvc2013\bin\moc.exe -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_PLUGIN -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -D_MSC_VER=1800 -D_WIN32 -IC:/Qt/5.6/msvc2013/mkspecs/win32-msvc2013 -IC:/dev/simNET/plugins/CreatorPlugin -IC:/dev/simNET/application -IC:/dev/_programme/FastRTPS1.5/include -IC:/Qt/5.6/msvc2013/include -IC:/Qt/5.6/msvc2013/include/QtWidgets -IC:/Qt/5.6/msvc2013/include/QtGui -IC:/Qt/5.6/msvc2013/include/QtANGLE -IC:/Qt/5.6/msvc2013/include/QtCore -I. ..\..\..\simNET\plugins\CreatorPlugin\CreatorPluginPublisher.h -o release\moc_CreatorPluginPublisher.cpp
..\..\..\simNET\application\P3DHook.h(13) : fatal error C1083: Cannot open include file: 'SimConnect.h': No such file or directory
It looks like it adds other include paths (such as the one for my DDS library) but it simply won't add the SimConnect one, no matter how often I rerun qmake.
Has anyone an idea what the problem could be?
EDIT:
I noticed that the build actually does not even fail. It successfully builds my project and creates the executable. For some reason QtCreator will still think the build failed and will show me that error. Running my executable manually without QtCreator works fine...
Solution was the following:
My application consists of 3 subprojects: the main gui application + 2 plugins, which include some main gui's source code. Now the error occured in the source code of the main application, but exactly that source code happened to be included by one of the plugins. In that plugins .pro file, there was no path given to the external SimConnect library though, which was the problem.
So... If you include source code from another of your projects, make sure to also include all the dependencies needed in that subproject. Because otherwise it might lead to a misunderstandable error message.
Maybe your include paths have some unrecognizable symbols.
What is your absolute paths?

Link dylib in macOs QT project

I tried a simple dylib in macOS and compiled with g++. I made a small sample to test the lib, it works perfect.
Now I made a simple QT app, linked the lib and added the header to the mainwindow.cpp and I always got a fail message Reason: image not found
I read the web and also some other cases here but all is basing on paths.I think it is is not a path problem. Because I made all changes I read in all the cases and also copied the lib in all needed folders, like project folder, build folder. Nothing helps.
I think that QT cannot work with the library and I missed some needed code, like for initialize or export. So that the problem is more inside the dylib and not in QT or Paths values.
Maybe someone can help me here out?
I have tried:
INCLUDEPATH += $$PWD/mylib
DEPENDPATH += $$PWD/mylib
macx: LIBS += -L$$PWD/mylib/ -lmylib
I tried to copy the lib to the build folder and also to the executable folder.
Also edited:
/⁨Users⁩/⁨ingoforster⁩/Documents⁩/Development⁩/Playground⁩/TestGround⁩/mylib:/Users/ingoforster/Qt/5.9.1/clang_64/lib
in Project settings DYLD_LIBRARY_PATH
Set also to DYLD_FRAMEWORK_PATH
Cpp
#include "mylib.hpp"
char *mMessage(void) {
return "Ein sonniger Tag";
}
header
#include <stdio.h>
#include <iostream>
using namespace std;
char *mMessage(void);
compiled with
g++ -std=c++0x --verbose -dynamiclib -o libmylib.dylib mylib.cpp
Sample
#include "mylib.hpp"
int main(void){
char* Ingo = mMessage();
std::cout << mMessage();
}
compiled with
g++ -std=c++0x test.cpp -L./ -lmylib
Actual result is that the sample runs perfect.
But in QT I got:
dyld: Library not loaded: libmylib.dylib
Referenced from: /Users/ingoforster/Documents/Development/Playground/build-TestGround-Desktop_Qt_5_9_1_clang_64bit-Debug/TestGround.app/Contents/MacOS/TestGround
Reason: image not found
10:09:05: The program has unexpectedly finished.
10:09:05: The process was ended forcefully.
/Users/ingoforster/Documents/Development/Playground/build-TestGround-Desktop_Qt_5_9_1_clang_64bit-Debug/TestGround.app/Contents/MacOS/TestGround appears to be compile-linked to your library code but perhaps has not been formally installed to the executable. macdeployqt usually deals with this issue.
You may also do this manually with otool and install_name_tool:
otool -L /path/to/executable
This will list the installed paths to the dylibs in use. You will see your dylib, that is the "/old/path/to/libmylib.dylib"
install_name_tool -change /old/path/to/libmylib.dylib /new/path/to/libmylib.dylib /path/to/executable
Usually, in an .app, the dylib is installed to a subdirectory within the .app folder.
Application.app/
Contents/
MacOS/
executable
Frameworks/
libmylib.dylib
With install_name_tool you can point to the dylib relative to the executable path to make the app portable.
install_name_tool -change /old/path/to/libmylib.dylib #executable_path/../Frameworks/libmylib.dylib /path/to/executable
After some hard investigation and running into the wrong direction with the given answers here I found out, that QTCreator will do all its own:
QTCreator Pro file have to contain:
macx: LIBS += -L$$PWD/mylib/ -lmylib
INCLUDEPATH += $$PWD/mylib
DEPENDPATH += $$PWD/mylib
MediaFiles.files += mylib/libmylib.dylib
MediaFiles.path = Contents/MacOS
QMAKE_BUNDLE_DATA += MediaFiles

ft2build.h: No such file or directory - Freetype 2.6

I am trying to build from Linux cause I decided to start using Jenkins, my personal work but, even with freetype installed: v.2.6.3, it doens't recognize this ft2build.h.
This is the QT Pro with freetype loaded. I'm now running on UBuntu 16.04:
linux {
message("Build for Linux")
DEFINES += LINUX
DEFINES += BOOST_LOG_DYN_LINK
LIBS += -lGLU
LIBS += -lfreetype
LIBS += -L/usr/lib/x86_64-linux-gnu/-libboost_timer.so -libboost_log.so -libboost_log_setup.so -libboost_system.so -libboost_thread.so -libboost_filesystem.so
}
So i tried to change also the lib pointer doing manually as:
LIBS *= -L/usr/local/lib/ -lfreetype
but still nothing going properly. The error I get is from lGLU
In file included from displays/display.cpp:3:0:
displays/./../oglft/oglft.h:50:22: fatal error: ft2build.h: No such file or directory
compilation terminated.
Makefile:1093: recipe for target 'display.o' failed
I do always run 'qmake make clean' then /usr/lib/x86_64-linux-gnu/qt5/bin/qmake && make && make check to be sure it starts properly. Can someone help me solving the bug?
I've checked where freetype lib is located by doing:
pkg-config --cflags --libs freetype2
and this is what I get
-I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype
PROBLEM SOLVED!
I have had to set FREETYPE in the environment variables as BOOST too and everything is now working properly!
Here is how is mine:
export BOOST=/var/lib/jenkins/workspace/boost_1_59_0
export FREETYPE=/var/lib/jenkins/workspace/freetype-2.6.3
I preferred to move those two libs under Jenkins to avoid permissions problems.
;-)

Adding Google's protocol Buffer to Qt ; Disable Compiler Warnings

In order to add the protobuf library from google to my Qt Project I did the following steps. I use Windows 10 and Qt 5.6 with the mingw32compiler.
1 Install protobuf
Therefore I installed MSYS with mingw and cd to the protobuf-3.0.0-beta-2 directory where I ran the configure script ./configure --prefix= 'cd /c/qt/Tools/mingw492_32/ ; pwd -W making sure to install protobuf in the Qt compiler directory. Afterwards I ran makeand make install.
2 Compile Project with protobuf
Now I add the include path INCLUDEPATH += C:/qt/tools/mingw492_32/includeand the library path LIBS += $$PWD/../protobuf-3.0.0-beta-2/src/libs/libprotobuf.a to my Qt project files to make the google protobuf available.
Compiling my project works but I receive a lot of warnings since the protobuf library has a lot of unused parameters / dummy functions. Is there any way to turn of the warnings obtained from the external protobuf library?
You need to tell the compiler that the protobuf headers are system headers. The -I flag tells the compiler where to look for non-system headers, whereas -isystem gives directories containing system headers. System headers do not produce warnings. But INCLUDEPATH uses -I.
Instead of:
INCLUDEPATH += C:/qt/tools/mingw492_32/include
Try:
QMAKE_CXXFLAGS += -isystem C:/qt/tools/mingw492_32/include

Linking freeglut with Qt Creator in Linux

I currently run Arch Linux on my laptop and was hoping to know why Qt Creator isn't finding my glut library (which exists on my system).
My setup qmake file looks as follows:
...
/*sources and headers above*/
QT += opengl
LIBS += -lfreeglut
INCLUDEPATH += -L/usr/lib/
And when I run a locate glut, I get the following:
/usr/include/kwinglutils.h
/usr/include/kwinglutils_funcs.h
/usr/include/GL/freeglut.h
/usr/include/GL/freeglut_ext.h
/usr/include/GL/freeglut_std.h
/usr/include/GL/glut.h
/usr/lib/libglut.a
/usr/lib/libglut.so
/usr/lib/libglut.so.3
/usr/lib/libglut.so.3.9.0
/usr/share/avogadro/fragments/amino_acids/D-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/D-glutamine.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamic_acid.cml
/usr/share/avogadro/fragments/amino_acids/L-glutamine.cml
/usr/share/licenses/freeglut
/usr/share/licenses/freeglut/LICENSE
/var/lib/pacman/local/freeglut-2.6.0-1
/var/lib/pacman/local/freeglut-2.6.0-1/changelog
/var/lib/pacman/local/freeglut-2.6.0-1/desc
/var/lib/pacman/local/freeglut-2.6.0-1/files
Note that I have tried -lglut32 in my qmake file as well.
What could I be missing here?
When you specify -lfoobar in your .pro file (or with gcc in general), you're directing the compiler to search for the library libfoobar.a. Judging from your locate output it looks like you want:
LIBS += -lglut
Oh, silly me. I just realized that the correct lib to add was just -lglut and not -lglut32. This is because there exists libglut.so, and not libglut32.so.