Results 1 to 13 of 13

Thread: Qt and Boost in the same C++ program?

  1. #1
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Question 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

  2. #2
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  3. #3
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

    cpp Code:
    1. #include <stdio.h>
    2. #include <wchar.h>
    3.  
    4. int main() {
    5. swprintf(0, 0, 0);
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 View Post
    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and Boost in the same C++ program?

    Quote Originally Posted by TriKri View Post
    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.

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt and Boost in the same C++ program?

    Quote Originally Posted by wysota View Post
    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 View Post
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and Boost in the same C++ program?

    Quote Originally Posted by TriKri View Post
    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().

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt and Boost in the same C++ program?

    Quote Originally Posted by wysota View Post
    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and Boost in the same C++ program?

    Quote Originally Posted by TriKri View Post
    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:

    C Code:
    1. extern int printf (const char *, ...);
    2.  
    3. int main() {
    4. printf("%i\n", 42);
    5. return 0;
    6. };
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    May 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

Similar Threads

  1. Replies: 1
    Last Post: 30th April 2010, 13:25
  2. Howto use Qt with Boost ?
    By bilgenratte in forum Qt Programming
    Replies: 3
    Last Post: 1st October 2009, 14:12
  3. how to use boost multi_array in QtCreator
    By elflord in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2009, 07:37
  4. Boost libraries
    By steg90 in forum General Programming
    Replies: 26
    Last Post: 13th June 2007, 12:50
  5. boost::assign
    By Sivert in forum General Programming
    Replies: 0
    Last Post: 2nd May 2007, 00:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.