Thread: How to set Boost up with MinGW?

  1. #1
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286

    How to set Boost up with MinGW?

    Hi,

    I have tried to find a good guide for how to set Boost up with MinGW, but there seems to be no good one. So I've tried a little on my own. Before I downloaded boost to my computer, my system looked like this:

    Windows 7 x86 (32 bit)
    MinGW 5.1.6
    MSYS 1.0

    The steps I took to set Boost up were the following:

    1. Downloading Boost 1.42.0 from sourceforge.net
    2. Extracting the archive to C:\Program1\
    3. Downloading a prebuilt executable of bjam 3.1.18 and putting it into a folder in my PATH
    4. Opening a command prompt window and typing the following:
    Code:
    cd C:\Program1\boost_1_42_0
    bjam --prefix=C:\Program1\boost_1_42_0 --toolset=gcc link=static install
    The last line here I basically just compiled from a number of very different looking (although doing the same thing) command lines I found on the web.

    After that I tried to compile an example program I found at the boost getting started guide, which looked like this:

    main.cpp
    Code:
    #include <boost/lambda/lambda.hpp>
    #include <iostream>
    #include <iterator>
    #include <algorithm>
    
    int main()
    {
        using namespace boost::lambda;
        typedef std::istream_iterator<int> in;
    
        std::for_each(
            in(std::cin), in(), std::cout << (_1 * 3) << " " );
    }
    The Makefile I wrote my self (since they didn't have any guide for how to make it compile with mingw), and it looks like this:

    Makefile
    Code:
    CC=g++
    CCFLAGS= -Wall -Wextra -pedantic -g -std=c++98
    CCFLAGS+=-IC:/Program1/boost_1_42_0 #$(BOOST_ROOT)
    CCFLAGS+=-lmingw32
    FILES=main.x
    SRC=$(FILES:.x=.cpp)
    OBJ=$(FILES:.x=.o)
    OUT=boost_test.exe
    
    all: $(OUT)
    	rm $(OBJ) #Remove .o files
    
    $(OBJ) :
    	$(CC) $(SRC) $(CCFLAGS) -c #Create .o files
    
    $(OUT) : $(OBJ)
    	$(CC) $(OBJ) $(CCFLAGS) -o $@ #Link .o files
    Compiling with "make -k" gave me the following output:

    Code:
    -*- mode: compilation; default-directory: "d:/Work/Programs/Test_programs/boost_test/" -*-
    Compilation started at Wed May 05 23:37:27
    
    make -k 
    g++ main.cpp -Wall -Wextra -pedantic -g -std=c++98 -IC:/Program1/boost_1_42_0  -lmingw32 -c #Create .o files
    In file included from c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/postypes.h:42,
                     from c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iosfwd:42,
                     from c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ios:39,
                     from c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/ostream:40,
                     from c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/iterator:65,
                     from C:/Program1/boost_1_42_0/boost/detail/iterator.hpp:54,
                     from C:/Program1/boost_1_42_0/boost/iterator/iterator_traits.hpp:8,
                     from C:/Program1/boost_1_42_0/boost/indirect_reference.hpp:15,
                     from C:/Program1/boost_1_42_0/boost/lambda/detail/operator_return_type_traits.hpp:17,
                     from C:/Program1/boost_1_42_0/boost/lambda/lambda.hpp:23,
                     from main.cpp:7:
    c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error: '::swprintf' has not been declared
    c:\program1\qt\2010.02.1\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error: '::vswprintf' has not been declared
    make: *** [main.o] Error 1
    make: Target `all' not remade because of errors.
    
    Compilation exited abnormally with code 2 at Wed May 05 23:37:30
    "error: '::swprintf' has not been declared", why do I get that message? (The only thing I can find about it is that it seems to be a bug in mingw, which have been corrected now - even though it still affects me.) Didn't my boost build properly for mingw; have I maybe used the wrong arguments for bjam, or have I forgot something? I think it's so strange that there is really no good guide for how to build boost for mingw. I mean, mingw's g++ must be one of the most common compilers used when writing c++ applications, at least if you prefer using your own text editor to visual studio.

    I would really appreciate help with this problem so I can get the code to compile. Thank you very much in advance.
    Come on, you can do it! b( ~_')

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It doesn't seem like the problem is related to boost, but rather some STL functions, since swprint is the wide-char version of sprintf.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    So, how can I fix this, or what could potentially be causing the problem? Anyone who has had the same problem before?

    Edit: I also found this about the problem: swprintf - GNU Gnulib. But according to this documentation, swprintf is existing under windows, only that it works a little bit differently. My compiler says that the function does not exist at all, not in any form. I guess it should do, since it seems to be located in the same include files in both linux and windows.
    Last edited by TriKri; 05-06-2010 at 09:20 AM.
    Come on, you can do it! b( ~_')

  4. #4
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Never mind, I will create a new thread. Thanks anyway for the help!
    Come on, you can do it! b( ~_')

  5. #5
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    The example code works fine with Visual Studio 2008, as expected. I think the problem is that Boost and MinGW are not guaranteed too work together; see the beginning of Boost's Getting Started on Windows guide. I'm changing to Visual Studio.
    Come on, you can do it! b( ~_')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading words into set
    By AJOHNZ in forum C++ Programming
    Replies: 3
    Last Post: 09-06-2009, 06:13 PM
  2. TCL Scripting
    By johndejesus in forum Tech Board
    Replies: 5
    Last Post: 08-07-2009, 03:35 AM
  3. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. Set default directory with GetTempDir?
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 05-04-2003, 11:36 PM

Tags for this Thread