Trouble using Botan with Qt - c++

I am using Qt and I am trying to use Botan. Everything seemed to go well, but when I go:
Botan::BigInt myInt;
In my constructor it works fine, but on the other hand if I go:
Botan::AutoSeeded_RNG rng;
It throws undefined errors:
C:\Users\Stevie\Desktop\asfsdf-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\mainwindow.o:-1: In function `AutoSeeded_RNG':
C:\Users\Stevie\Desktop\asfsdf-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\..\..\..\..\botan\include\botan\auto_rng.h:40: error: undefined reference to `_imp___ZN5Botan23Global_State_Management12global_stateEv'
C:\Users\Stevie\Desktop\asfsdf-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\..\..\..\..\botan\include\botan\auto_rng.h:40: error: undefined reference to `_imp___ZN5Botan13Library_State10global_rngEv'
:-1: error: collect2: ld returned 1 exit status
I have no idea why it would work with a BigInt but not the AutoSeeded_RNG, but here are my exact steps:
Compiled the Botan source included in the Qt Creator source at "src/libs/3rdparty/botan/"
I installed Botan using the Windows Installer (1.10) from their website.
I took the libBotan.a, libBotand.a, botan.dll, and Botand.dll and put them in the location where I installed Botan (C:\botan). I overwrote any of those files that already existed.
I then created a new Qt project, and inside of the .pro file I added the following lines:
INCLUDEPATH += "C:/botan/include"
LIBS += "C:/botan/libBotan.a"
Next, I go into my "mainwindow.cpp", and add:
#include <botan/botan.h>
Everything compiles up to here successfully.
I now add this to my constructor:
Botan::AutoSeeded_RNG rng;
Now the above errors are thrown, and cannot be ran. If I replace the "AutoSeeded_RNG" with "BigInt", then it compiles perfectly.
Thanks for any help, Hetelek.

The statement to link against the Botan library looks strange to me. Normally, you specify library directories using the -L switch and add a library with the -l switch, i.e you should use
LIBS += -L"C:\botan" -lBotan
Note that the prefix and suffix of the library are not specified in lbotan. The linker will automatically look for a libbotan.a or botan.dll, depending on your environment.
Botan is also part of QtCreator. Maybe you should have a look at their repository. You can find .pri and .pro files there and probably only need to copy them. They also have written a .qbs driver for the new Qt build system.
Edit: I just compiled Botan from the QtCreator sources, as you also mentioned in your post. I then copied all the generated libraries in my own directory and I also used the botan.h which was shipped with QtCreator. On Linux I had to add
LIBS += -L"/dir/into/which/i/copied/botan/dlls" -LBotan -ldl
to the qmake .pro file. Note the additional -ldl otherwise I got undefined references to dlym, dlerror etc. I could compile a simple example with Botan::AutoSeeded_RNG without problems.

Related

Using grpc with QtCreator, undefined reference to `grpc::...`

I am trying to write some code in C++ in QtCreator to connect to a grpc server when I get this compiler error:
/some/path/serverproxy.cpp:40: error: undefined reference to `grpc::InsecureChannelCredentials()'
Here's my grpc includes at the top of serverproxy.cpp
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
#include <grpc++/security/credentials.h>
and the error comes from this line:
somenamespace::NewStub(
grpc::CreateChannel("someaddress",
grpc::InsecureChannelCredentials()))};
I tried adding existing files and adding these headers in QtCreator (although it would be very strange to have to do that manually for the headers to all external libraries), but it didn't work. They are located at /usr/local/include/grpc++/**/*.h.
Also tried adding INCLUDEPATH += /usr/local/include to my .pro file.
I also tried cleaning the project, running qmake and building again.
What do I have to do to be able to use these grpc++ functions?
I looked at so many undefined reference in qtcreator threads without noticing this, which I finally saw here which is what got rid of the undefined reference errors:
You are facing a link error. Just add in your .pro the path to your
lib and its name with :
LIBS += -L<path_to_the_lib> -l<libName>
specifically
LIBS += -L/usr/local/include/grpc++ -lgrpc++

Can't link ncurses with Qt

I included <ncurses.h> , but can't link ncurses's libs in .pro file. I'm trying like this:
LIBS += -L"/usr/lib/" -libncurses.a
I tried different variations of linking (with/without file_type, different variations of directory), but it didn't help. Then I decided to link via console using:
g++ -lncurses main.cpp snake.cpp
Tried to put -lncurses in different places of command.
It gives me an error:
undefined reference to move(); (ncurses's func)
And it doesn't want to compile C++11 features, like std::list.empalce_front();. The reason I'm asking for help for second problem in the same question, is that if would able compile only via console, so i won't be able to use C++11 features, but i want to!
P.S. Of course, the main problem is with linking ncurses's libs
http://www.lucidarme.me/?p=3961 Here You can find a solution. Main reason is You incorrectly set project:
LIBS += -lncurses
Check a link I sent You. Everything is there clear.

OpenGL with Eclipse CDT + MinGW + GLEW + GLFW: Undefined References

Edit: I have in the meantime figured this out and written a detailed answer below.
I just tried switching from the Express version of MSVC 10 to Eclipse CDT on Win7, and while configuring I encountered a problem with the following simple OpenGL code (which works fine in Visual Studio):
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
GLFWwindow* w;
if (!glfwInit())
return -1;
w = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!w)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(w);
glewExperimental = true;
if (glewInit() != GLEW_OK)
{
return -1;
}
while (!glfwWindowShouldClose(w))
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(w);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
In Visual Studio, I include the library paths for GLFW and GLEW, and link (in addition to the stuff that VS does built-in) opengl32.lib, glew32s.lib, glfw3.lib, in that order.
Now if I do the same in Eclipse CDT, I can't get it to work. The following errors occur:
Info: Internal Builder is used for build
g++ "-LD:\\lib\\cpp\\glfw-3.0.1.bin.WIN32\\lib-mingw" "-LD:\\lib\\cpp\\glew-1.10.0binaries\\lib\\Release\\Win32" -o glfwcheck.exe main.o -lopengl32 -lglew32s -lglfw3
Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
D:\lib\cpp\glew-1.10.0binaries\lib\Release\Win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text[__glewInit_GL_VERSION_1_2]+0x4): undefined reference to `_imp__wglGetProcAddress#4'
D:\lib\cpp\glew-1.10.0binaries\lib\Release\Win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text[__glewInit_GL_VERSION_1_3]+0x4): undefined reference to `_imp__wglGetProcAddress#4'
d:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: D:\lib\cpp\glew-1.10.0binaries\lib\Release\Win32/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj): bad reloc address 0x4 in section `.text[__glewInit_GL_VERSION_1_3]'
d:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Of course I tried changing the order of the three libraries, but that only mad it worse. (By the way: I think it's strange that I can't reproduce these errors above such that they're the only ones when I re-arrange the libs to the initial order. I stay at 20+ errors until I delete ALL the libs, build, and add them again.)
After fumbling around and looking through forum posts, I figured that maybe it's a problem with the GLEW binaries, and compiled them on my own with MinGW. Only this time, I get all the 'not found' errors. I don't know how I can link statically with my self-compiled GLEW, since there's now no glew32s.lib any longer, but only libglew32.a and libglew32mx.a. Linking dynamically with glew32 and putting the dll into my project folder didn't work either.
I feel like I'm doing something very wrong here in Eclipse, or just forget some additional libraries (although I once tried putting all the ones VS uses in there as well and it still did the exact same thing).
Can you help me out? :) Otherwise I think I'd have to stay with VS, or switch to Linux + make.
I figured it out, and for anyone ever encountering the issue I will try and make clear what exactly I did to finally be able to create OpenGL projects with the setup MinGW + GLEW + GLFW. In my case, I used Eclipse CDT as IDE, but I'll write down the resulting g++ command line so it should be easy to adapt to other IDE's.
I'll suppose MinGW and MSYS (can be chosen to be installed from within the MinGW GUI; thus no need to download separately) are installed.
Download GLFW and unzip it in your external libraries folder of choice (in my case, this is D:\external\cpp, so it would be something along the lines of D:\external\cpp\glfw, where I renamed the glfw-3.0.3.bin.WIN32 folder to simply glfw).
Download the GLEW source as a zip folder an unzip it, in my case it's in D:\external\cpp\glew. Now start MSYS, cd to the glew folder and invoke make all.
Step 3 should have created (among others) the files libglew32.a and glew32.dll inside the folder glew\lib. Now right click your Eclipse CDT C++ project, go to Properties - C/C++ General - Paths and Symbols. In the Includes tab, add the paths to the include folders of GLFW and GLEW. Again, for me this is D:\external\cpp\glew\include and analogous for GLFW. In Library Paths, do the same for the folders lib (GLEW) and lib-mingw (GLFW).
Now we have to add the libraries we want our project to be linked with. If you wish to link with GLEW dynamically, make sure to include the glew32.dll in the folder where your executable will be. In Eclipse CDT, that's usually the Debug (or Release) folder in your project structure. In the Libraries tab in the options window we opened before, add (the order is important!) glfw3, glew32, opengl32, glu32, gdi32. Now building the project should work hopefully. In case you want to link statically with GLEW, add the same libraries with the exception of glew32. Instead, in the project properties go to C/C++ Build - Settings and in the Tool Settings - MinGW C++ Linker - Miscellaneous tab add the path to libglew32.a to the Other objects field. In my case, this is D:\external\cpp\glew\lib\libglew32.a. Now in order for the static linking to work, you have to either add #define GLEW_STATIC above #include <GL/glew.h> or use the preprocessor command -DGLEW_STATIC. The GLEW homepage says that it's also possible to include the glew.c and glew.h files into your project in order to link statically, but somehow this didn't really work out for me.
These steps worked for me, and they produced command lines similar to the following (I have only one file named main.cpp and used static linking with GLEW), which could be useful if you're trying to figure this matter out without Eclipse CDT.
g++ -ID:\external\cpp\glew\include -ID:\external\cpp\glfw\include -c -o main.o main.cpp
g++ -LD:\external\cpp\glew\lib -LD:\external\cpp\glfw\lib-mingw -o minimalexample.exe main.o D:\external\cpp\glew\lib\libglew32.a -lglfw3 -lopengl32 -lglu32 -lgdi32
In the dynamic linking case, simply remove the part containing libglew32.a in the second line, and add -lglew32 between -lglfw3 and -lopengl32. As a little example source file, you could just use the code in my above question.
I hope I can help anyone with this, as I sure saw me having a lot of trouble figuring this out between tens of error messages of unresolved symbols and various other problems :-)
Update: I tried to go over this again some days ago and ran into problems with the pre-compiled GLFW binaries for Windows (I'm now using Win8.1). But you can just use CMake in combination with mingw32-make to compile it on your own. Also, GLEW seems to not be getting updates anymore, so I switched to glad instead. It's also possible to use MinGW-w64 to compile the libraries and your final project as 64-bit application.

Errors while trying to compile with external libraries

I have downloaded the mimetic library installation files,
and followed the INSTALL instructions.
./configure
a script that creates the make file after checking a series of things.
make
compiles the cpp files, after this different .o and .lo files appear in the original folder.
make install
seems to do a lot but the only thing that I seem to notice is that a mimetic directory
appears under /usr/local/include with all the header files.
than I try to compile the most simple main file possible:
(as offered in the library site : original example )
#include <mimetic/mimetic.h>
using namespace mimetic;
int main()
{
MimeEntity me;
return 0;
}
I am compiling with following command ( on CentOS 5.7, gcc version : 4.1.2 ):
g++ mimetic.cpp
The error I get:
/tmp/ccWnsteO.o: In function `main':
mimetic.cpp:(.text+0x80): undefined reference to `mimetic::MimeEntity::MimeEntity()'
mimetic.cpp:(.text+0x91): undefined reference to `mimetic::MimeEntity::~MimeEntity()'
collect2: ld returned 1 exit status
From this I understand that the header files are found but the source/library itself
is missing.
the MimeEntity constructor declaration appears in : /usr/local/include/mimetic/mimeentity.h
when I do a search for mimeentity I get the following :
/home/mimetic-0.9.7/mimetic/mimeentity.o
/home/mimetic-0.9.7/mimetic/mimeentity.h
/home/mimetic-0.9.7/mimetic/mimeentitylist.h
/home/mimetic-0.9.7/mimetic/mimeentity.cxx
/home/mimetic-0.9.7/mimetic/.libs/mimeentity.o
/home/mimetic-0.9.7/mimetic/mimeentity.lo
/home/mimetic-0.9.7/mimetic/.deps/mimeentity.Plo
/usr/local/include/mimetic/mimeentity.h
/usr/local/include/mimetic/mimeentitylist.h
I've tried with a search path to the libraries but the same error appears
g++ mimetic.cpp -L/home/mimetic-0.9.7/mimetic/
Something else strange is happening, when I try to compile the main mimetic.cpp file
with the line
MimeEntity me;
changed to
MimeEntity me();
it compiles.
You are getting a linker error simply because you are not referencing the library when compiling the test source file. It needs to be something like:
g++ mimetic.cpp -l<libraryname>
The reason it compiles when you add the braces is that you are really declaring a function called 'me' that returns a MimeEntry. While it compiles, it does not do what you want.
The command you are using to build your mimetic example seems incomplete. You are specifying library search patch (-L) but not the library itself.
Make sure that -L option specified the location of the mimetic library
Add -l'the-name-of-the-mimetic-library'. My guess would be -lmimetic
Add -I (that is capital i) option for the location of the headers.

Compiler Command Line in Qt (Boost Related)

I have a problem when using <boost/thread.hpp> in my code. When I try to compile it in Qt, I get these errors:
undefined reference to boost::system::generic_category()
undefined reference to boost::system::generic_category()
undefined reference to boost::system::system_category()
error: ld returned 1 exit status
Anyway, I searched StackOverflow and found this:
Undifined Reference With Boost When I Try To Compile
They say the key to solve this problem is adding -lboost_system. But where should I add this?? :( I'm a newbie in boost and Qt and I want don't wanna compile my programs using command-line directly. Is there a way to add these command-line options to Qt Creator?
I use Qt 5 with MinGW compiler and Boost 1.53. Thanks.
Add it to your .pro file:
LIBS += -L<their location> -lboost_system
I'm assuming that you have the boost_system library installed in a place the compiler will look of course.