Qt and Boost in the same C++ program?
Hi, I'm trying to create a program which is both going to use Qt and Boost. I realized after trying for a day or so that Boost programs cannot be compiled using MinGW, because of a non existing swprintf function. So I changed to Visual Studio 2008. Then, I could compile a simple boost program, but I don't know how to compile a qt program. Since I have to use qmake to create a makefile, I guess I can't use the normal Build->Build Solution in the Visual Studio menu, so I tried the following:
1. Open Visual Studio 2008 Command Prompt (to get the desired environment with the appropriate environment variables)
2. cd to the directory
3. type "qmake -project" (or create my own .pro file)
4. type "qmake"
5. type "nmake"
And now the Qt program compiles. However, I don't think I'm doing this in the right way, since when I'm adding stdint.h to the included files, the compiler (cl.exe) complains about not being able to open the file.
Besides, how do I tell the compiler (cl.exe, nmake, qmake, whatever I have to tell it to) to link against boost? My boost is set up in the static multithreaded variants.
Thanks in advance!
-Kristofer
Re: Qt and Boost in the same C++ program?
Is there really no one who can answer these questions? I'm wondering if, firstly: I am doing right when I'm compiling this test program (running first "qmake -project", then "qmake", then "nmake", from the visual studio command prompt), since the compiler seems to be unable to find stdint.h when I'm compiling it like this, and secondly: How to tell the compiler to link the program againts boost?
Please, I really need to get these questions answered, so I can compile this program! I already have a quite big Qt application developed in MinGW; now I only have to integrate it with boost. Thank you in advance.
-Kristofer
Re: Qt and Boost in the same C++ program?
I just found out that stdint.h is not shipped with visual studio; that's why the compiler didn't find the file :p Right now I'm compiling directly from visual studio, I found a video on youtube which showed me how to set visual studio up against Qt, and how to create the appropriate project. But if I will decide to move over to compiling from the visual studio command prompt again, I will try adding "INCLUDEPATH += . /usr/local/include/boost-1_33_1/" to my .pro file. Then I would also have to stop writing "qmake -project" every time I compile, since the only thing it does is to create a new .pro file and overwrite the already existing one.
-Kristofer
Re: Qt and Boost in the same C++ program?
Somehow I can't believe boost can't be built with MinGW. swprintf() is a standard C99 function so MinGW runtime has to implement it.
Can you try to compile this app with MinGW? Just don't run it, it would crash.
Code:
#include <stdio.h>
#include <wchar.h>
int main() {
swprintf(0, 0, 0);
return 0;
}
Re: Qt and Boost in the same C++ program?
Well, your code does compile with MinGW. I don't know why I get that error when I use boost - strange. Seems like boost doesn't include all the libraries needed? I have no idea why otherwise. Anyway, the example code from boost's home page compiles in visual studio, and that is what I am using now.
Quote:
Originally Posted by
wysota
swprintf() is a standard C99 function so MinGW runtime has to implement it.
C99 is a C standard, so MinGW's g++ doesn't have to implement it (if not C++98 covers it of course, I don't know about that). But maybe g++ in principle implements as much as possible from the C99 standard without differing from C++98.
Re: Qt and Boost in the same C++ program?
Quote:
Originally Posted by
TriKri
Well, your code does compile with MinGW. I don't know why I get that error when I use boost - strange. Seems like boost doesn't include all the libraries needed?
But no libraries are needed here.
Quote:
C99 is a C standard, so MinGW's g++ doesn't have to implement it (if not C++98 covers it of course, I don't know about that). But maybe g++ in principle implements as much as possible from the C99 standard without differing from C++98.
Hmm...? You know there is no "C++ runtime" only "C runtime", right? g++ is just a compiler, it doesn't implement functions. C runtime does (i.e. (g)libc on gcc unix platforms).
Re: Qt and Boost in the same C++ program?
Quote:
Originally Posted by
wysota
But no libraries are needed here.
What do you mean? I'm including libraries in both cases, so don't I need libraries in both cases? Or do you mean that if I include these files before I include the boost libraries, I won't get these compile errors?
Quote:
Originally Posted by
wysota
Hmm...? You know there is no "C++ runtime" only "C runtime", right? g++ is just a compiler, it doesn't implement functions. C runtime does (i.e. (g)libc on gcc unix platforms).
I don't really know what MinGW Runtime means, but I found this about it:
Quote:
Originally Posted by http://74.63.13.247/index.php/mingw-runtime
The MinGW Runtime is the package of headers and libraries that describe the API for the MSVCRT and the mingwex extension functions to help support C99.
Does MinGW Runtime also help support C++98? For example, stdint.h is a C99 standard library, but it is not implemented in the C++98 standard. In fact, if you include stdint.h in a visual studio project, it won't build because the VC++ compiler will not find the file. I thought it might have been the same thing with swprintf, but apparently not. Maybe stdint.h is just not implemented in C runtime?
Re: Qt and Boost in the same C++ program?
Quote:
Originally Posted by
TriKri
What do you mean? I'm including libraries in both cases, so don't I need libraries in both cases?
I mean you don't need any libraries to use swprintf().
Quote:
For example, stdint.h is a C99 standard library, but it is not implemented in the C++98 standard.
stdint.h is a header file, not a library. It's neither included in C99 nor in C++98 because it's a file. C99 and C++98 define the syntax and semantics of the language, not any files.
Re: Qt and Boost in the same C++ program?
Quote:
Originally Posted by
wysota
I mean you don't need any libraries to use swprintf().
Can you please explain this a bit more carefully? Okay, you don't need any library to use swprintf(), but you have included libraries anyway, why? Please explain this to me so I understand what you mean.
Re: Qt and Boost in the same C++ program?
Quote:
Originally Posted by
TriKri
Can you please explain this a bit more carefully? Okay, you don't need any library to use swprintf(), but you have included libraries anyway, why?
.h files are not libraries. They are declarations of functions, other symbols and sets of macros. You could as well simply copy their required contents to your main implementation file:
Code:
extern int printf (const char *, ...
);
int main() {
return 0;
};
Re: Qt and Boost in the same C++ program?
Aha, ok, my fault! I mean: Seems like boost doesn't include all the headers needed? :)
Re: Qt and Boost in the same C++ program?
I won't argue with that but maybe you just need to set some macro or something like this. swprintf() is declared in wchar.h, if that's of any help to you.
Re: Qt and Boost in the same C++ program?
It was just a guess, I have no idea actually why it's complaining. I think that use of functions like this should be hidden from the user, and I shouldn't have to mind about where different functions are located just because boost cannot find them, so I hope it's not the meaning that I should include these headers myself.
According to the top of this page, boost it may or may not work on the MSYS command shell, but I guess that doesn't mean that boost won't support mingw even if the normal command shell is used. I did have MSYS installed, although I compiled from the normal command shell. I don't know if this could have affected in any way.
Thanks anyway. Maybe mingw works with boost after all, just that I have done something wrong. :)
-Kristofer