• Using Boost C++ libraries with gcc g++ under Windows(cygwin+netbeans)


    1. Thanks for Stefan Fischerländer’s work(Stefan Fischerländer’s Blog)
    2. Install Cygwin. Make sure that you also install gcc, g++, boost, make and gdb – you should find all of them within the Devel section of the Cywin installer.
    3. Put your Cygwin home and Cygwin bin directory in your PATH variable. In my case I had to add C:\cygwin\home;C:\cygwin\bin; to my PATH variable. (Some help for changing the PATH variable.)
    4. Now open a windows command prompt and execute the following statements: ‘gcc –version’, ‘g++ –version’, ‘make –version’ and ‘gdb –version’. You should get something like this:
      C:\Dokumente und Einstellungen\sf>gcc --version
      gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
      Copyright (C) 2004 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    5. Now install Netbeans. After installation, open Tools – Plugins. Under “Available Plugins” you should see “C/C++”. Install this plugin and restart Netbeans.
    6. Now open, again in Netbeans, Tools – Options – C/C++. In the section “Build Tools” click “Add ..” and choose your Cygwin bin directory (C:\cygwin\bin) as your base directory and click “Okay”. Netbeans now finds all your compiler and make tools from the Cygwin installation.
    7. In the section “Code Assistance” you have to choose the sub-section “C++ Compiler”. Add the include directory for your Boost libraries: In my installation this is C:\cygwin\usr\include\boost-1_33_1. Click “Okay”.
    8. Create a new Netbeans C++ project and write some code. Right click your project and choose “Set Configuration – Manage Configurations …”. In the “C++ Compiler” section, include the path to your Boost libraries int the “Include Directories” folder. My path is C:\cygwin\usr\include\boost-1_33_1.
    9. In the “Linker” section put your Cygwin bin directory (C:\cygwin\bin) in the “Additional Library Directories” field. Then edit the “Libraries” field below: Click “Add Library File …”, change file type to “.dll” and choose the libraries you need for your project. For my small regex example, I need cyboost_programm_options-gcc-mt-1_33_1 and cyboost_regex-gcc-mt-1_33_1. (ps:the dlls which are in cygwin\bin.)
    10. While editing your C++ file, hit F6 and Netbeans will compile, link and start your programm. You’re finally done.

    This is my example code:

    #include <iostream>

    #include <string>

    #include <boost/regex.hpp>

    using namespace std;

    using namespace boost;

    int main() {

        string s = "This is my simple sample text, really.";

        regex re(",|:|-|\\s+");

        sregex_token_iterator my_iter(s.begin( ), s.end( ), re, -1);

        sregex_token_iterator my_end;

        while (my_iter != my_end)

            cout << *my_iter++ << '\n';

        return (EXIT_SUCCESS);

    }

    You can also build this little program on the command line. Open your Cygwin Bash Shell and navigate to your code directory. (Cygwin maps your windows drives under /cygdrive – thus cd /cygdrive/c/ navigates you to your windows C:\ drive.)
    To compile your source file called regexp.cpp, just type:
    g++ -c -I/usr/include/boost-1_33_1/ -o regexp.o regexp.cpp
    And to link and build it:
    g++ -o regexp.exe regexp.o -lboost_program_options-gcc-mt-s -lboost_regex-gcc-mt-s
    That’s all. Now type
    ./regexp.exe to start your compiled program.
  • 相关阅读:
    php 本周的起始时间
    获取微信公众号素材模板id
    复活贴
    Net 4.0 Parallel 编程(四) Task(上)
    Windows Phone 实用开发技巧120合集(电子书+源代码)
    Net 4.0 Parallel 编程(九)Task中的数据共享(下)
    收藏别人的小类库
    将DLL程序集加入GAC后的一系列问题汇总,及解决方法
    Net 4.0 Parallel 编程(七)Task中的数据共享(上)
    内存做硬盘,开启readyboost加速,全面提升系统性能!
  • 原文地址:https://www.cnblogs.com/smartvessel/p/1610554.html
Copyright © 2020-2023  润新知