How to use Boost in Visual Studio 2010

后端 未结 13 1087
情歌与酒
情歌与酒 2020-11-22 07:14

What is a good step by step explanation on how to use the Boost library in an empty project in Visual Studio?

13条回答
  •  感情败类
    2020-11-22 07:34

    Download boost from: http://www.boost.org/users/download/ e.g. by svn

    • Windows -> tortoise (the simplest way)

    After that : cmd -> go to boost directory ("D:\boostTrunk" - where You checkout or download and extract package): command : bootstrap

    we created bjam.exe in ("D:\boostTrunk") After that : command : bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static (It will take some time ~20min.)

    After that: Open Visual studio 2010 -> create empty project -> go to project properties -> set:

    Project properties VS 2010

    Paste this code and check if it is working?

    #include 
    #include 
    #include 
    
    using namespace std;
    
    struct Hello 
    {
        Hello(){ 
            cout << "Hello constructor" << endl;
        }
    
        ~Hello(){
            cout << "Hello destructor" << endl;
            cin.get();
        }
    };
    
    
    int main(int argc, char**argv)
    {
        //Boost regex, compiled library
        boost::regex regex("^(Hello|Bye) Boost$");
        boost::cmatch helloMatches;
        boost::regex_search("Hello Boost", helloMatches, regex);
        cout << "The word between () is: " << helloMatches[1] << endl;
    
        //Boost shared pointer, header only library
        boost::shared_ptr sharedHello(new Hello);
    
        return 0;
    }
    

    Resources : https://www.youtube.com/watch?v=5AmwIwedTCM

提交回复
热议问题