티스토리 툴바


1) Boost 라이브러리 홈페이지: www.boost.org (2012년 2월 24일 최신 버전은 1.48.0)

2) Boost 라이브러리 소스 내려받기: http://sourceforge.net/projects/boost/files/boost/1.49.0/

3) 이 문서 작성에 참고한 자료: Boost getting on Windows

4) 이래는 Boost 라이브러리 홈페에지;에 게시된 글...

Boost provides free peer-reviewed portable C++ source libraries.

We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.

We aim to establish "existing practice" and provide reference implementations so that Boost libraries are suitable for eventual standardization. Ten Boost libraries are included in the C++ Standards Committee's Library Technical Report (TR1) and in the new C++11 Standard. C++11 also includes several more Boost libraries in addition to those from TR1. More Boost libraries are proposed for TR2.

 

Boost 1.49.0 설치하고 테스트하기

[단계 1] 압축 파일을 적당한 곳에 풀어 놓는다.  (여기서는 D:\boost_1_49_0 에 풀에 놓은 것으로 간주한다.)

 

[단계 2] Visual Studio 2010 의 명령 프롬프트를 열고, Boost 의 주 디렉토리로 간다.

프롬프트> D:

프롬프트> cd \boost_1_49_0

 

[단계 3] 예제 파일 example.cpp 파일을 컴파일한다.

// Filename: example.cpp
//
// Compile: cl /EHsc example.cpp -I d:\boost_1_49_0
// Execute: echo 1 2 3 | example

#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) << " " );
}

 

프롬프트> cl /EHsc example.cpp -I d:\boost_1_49_0

 

[단계 4] 생성된 실행 파일 example.exe 파일을 실행한다.

프롬프트> echo 10 20 30 | example

 

[단계 5] 예제 파일 example2.cpp 파일을 컴파일한다.

// Filename: example2.cpp
//
// Compile: cl /EHsc example2.cpp -I d:\boost_1_49_0 /MD /link /LIBPATH:d:\boost_1_49_0\stage\lib
// Execute: example2 < jayne.txt

#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}
/*
Execution Result:
Will Success Spoil Rock Hunter?
*/

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link LIBPATH:d:\boost_1_49_0\lib

   라이브러리가 아직 빌드되지 않았으므로 당연히 (라이브러리 없음) 에러가 발생한다.

 

[단계 6] 일괄파일 bootstrap.bat 파일을 실행한다.

프롬프트> bootstrap

 

[단계 7] b2.exe 파일을 실행한다.

프롬프트> b2

 

[단계 8]  시간이 꽤 걸리므로 (볼일을 본 후) 한 두시간 후에 다시 컴에 돌아온다.

 

[단계 9]  생성된 lib 파일들을 확인한다.

프롬프트> dir stage\lib

 

[단계 10] 다시 example2.cpp 를 컴파일한다,

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link LIBPATH:d:\boost_1_49_0\lib

LINK : fatal error LNK1104: 'libboost_regex-vc100-mt-s-1_49.lib' 파일을 열 수 없습니다.

아직도 필요한 라이브러리 libboost_regex-vc100-mt-s-1_49.lib 가 없다는 에러 메시지이다.

 

[단계 11] 라이브러리 경로를 잘 지정하고 다시 example2.cpp  를 컴파일한다,

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /link LIBPATH:d:\boost_1_49_0\stage\lib

LINK : fatal error LNK1104: 'libboost_regex-vc100-mt-s-1_49.lib' 파일을 열 수 없습니다.

그래도 라이브러리 libboost_regex-vc100-mt-s-1_49.lib 가 없다고 한다.

실제로 폴더 d:\boost_1_49_0\stage\lib 를 탐색기로 확인해 보아도 그런 파일은 없다.

 

[단계 12] 이번에는 옵션 /MD 를 주고 다시 example2.cpp  를 컴파일해 본다,

프롬프트> cl /EHsc example2.cpp -I d:\boost_1_49_0 /MD /link LIBPATH:d:\boost_1_49_0\stage\lib

아주 깨끗하게 콤파일된다. (아래는 컴파일되면서 컨솔에 출력되는 메시지)

/out:example2.exe
/LIBPATH:d:\boost_1_49_0\stage\lib
example2.obj

 

[단계 13] 실행 파일 example2.exe  을 싱행하기 전에 다음 내용의 텍스트 파일을 jayne.txt 라는 이름으로 저장한다.

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.

 

[단계 14] 실행 파일 example2.exe 를 실행한다.

프롬프트> testBoost2 < jayne.txt
Will Success Spoil Rock Hunter?

 

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by Scripter

트랙백 주소 :: http://scripting.tistory.com/trackback/520 관련글 쓰기

댓글을 달아 주세요

  1. 김봉상 2012/05/12 23:28  댓글주소  수정/삭제  댓글쓰기

    명령어 프롬프트에서 cㅣ (씨 엘) 이 맞는지 모르겠네요....
    쳐보니까 cl이라는 내부 명령이 없다고 나오는데....

    덕분에 boost lib 입문자인데 무리없이 설치했습니다. 감사합니다.

Quick Sort 알고리즘을 이용하여 C 스트링들을 분류하는 소스입니다.


#include를 #import로 바꾼 것 외에는 C 소스와 똑 같습니다.

Dev-C++  IDE 에서도 캄파일과 실행이 잘 됩니다.

-----------------------------------------------------------------
/**
 * Filename: testSort.m
 *
 * Compile: gcc -o testSort testSort.m -lobjc
 * Execute: ./testSort 하나 둘 셋 넷
 *          ./testSort one two thee four
 *
 * Date: 2012/05/02
 * Author: pkim (AT) scripts.pe.kr
 */

#import <stdio.h>
#import <string.h>

char SBUF[20][80];
char TBUF[80];

void quickSort(char array[20][80], int start, int end);
void swap(char array[20][80], int x, int y);
void printArray(char array[20][80], int start, int end);
void exit(int n);

int main(int argc, char* argv[]) {
    char* pbuf;
    int i;
    if (argc > 1 && argc < 22) {
        for (i = 0; i < argc - 1; i++) {
            if (strlen(argv[i+1]) > 79) {
                printf("Caught: strlen(\"%s\") = %d, which is too long.\n", argv[i+1], strlen(argv[i+1]));
                exit(1);
            }
            sprintf(SBUF[i], argv[i+1]);
        }
        quickSort(&SBUF[0], 0, argc - 2);
        printArray(SBUF, 0, argc - 2);
    }
    else if (argc > 21) {
        printf("Given too many items. (The counter of items should be less then 20.)\n");
        exit(1);
    }
    return 0;
}

void quickSort(char array[20][80], int start, int end) {
    int i = start;
    int k = end;
    char pivot[80];

    if (end - start >= 1) {
        strcpy(pivot, array[start]);
        while (k > i) {
            while (strcmp(array[i], pivot) <= 0 && i <= end && k > i)
                i++;
            while (strcmp(array[k], pivot) > 0 && k >= start && k >= i)
                k--;
            if (k > i) {
                swap(array, i, k);
            }
        }
        swap(array, start, k);

        quickSort(array, start, k - 1);
        quickSort(array, k + 1, end);
    }
    else {
        return;
    }
}

void swap(char array[20][80], int x, int y) {
     strcpy(TBUF, array[x]);
     strcpy(array[x], array[y]);
     strcpy(array[y], TBUF);
}

void printArray(char array[20][80], int start, int end) {
    int i;
    printf("[");
    for (i = start; i < end; i++) {
        printf("%s, ", array[i]);
    }
    if (end >= start)
        printf("%s", array[end]);
    printf("]\n");
}
/*
실행 및 실행 결과:
$ ./testSort 하나 둘 셋 넷
[넷, 둘, 셋, 하나]

$ ./testSort one two thee four
[four, one, thee, two]
*/
------------------------------------------------


컴파일> Dev-C++ 개발 도구(IDE)에서 Ctrl+F11 클릭
또는
컴파일> gcc -o testSort testSort.m -lobjc


실행> testSort 하나 둘 셋 넷
[넷, 둘, 셋, 하나]

실행> ./testSort one two thee four
[four, one, three, two]


 

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by Scripter

트랙백 주소 :: http://scripting.tistory.com/trackback/518 관련글 쓰기

댓글을 달아 주세요


초등학교 때 배우는 두 정수의 곱셈표를 만들어 주는 C 소스이다.

/* * Filename: makeMultTableMain.m * * Print a multiplication table. * * Compile: Click Ctrl+F11 on Dev-C++ IDE * Execute: makeMultTable 230 5100 * * Date: 2012/05/01 * Author: pkim (AT) scripts.pe.kr */ #import <Foundation/Foundation.h> #import <stdio.h> #import <string.h> #import <math.h> void printUsing(); void printMultTable(long x, long y); int main(int argc, const char *argv[]) { long x, y; if (argc >= 3) { x = atoi(argv[1]); y = atoi(argv[2]); printf("\n"); printMultTable(x, y); } else { printUsing(); } return 0; } void printUsing() { // printf("Using: makeMultTable [number1] [number2]\n"); // printf("Print a multiplication table for the given two integers.\n"); printf("사용법: makeMultTable [자연수1] [자연수2]\n"); printf("(손으로 계산하는) 곱셈 계산표를 출력해 줍니다.\n"); } void printMultTable(long x, long y) { long nx, ny; long z; int ntail1; int ntail2; int n; int y1; int i; char strX[80]; char strY[80]; char strZ[80]; char strT[80]; char zeros[80]; char whites[80]; char bars[80]; char line1[80]; char line2[80]; char line3[80]; char line4[80]; char loffset[20]; char buf[80]; nx = (x >= 0) ? x : - x; ny = (y >= 0) ? y : - y; ntail1 = 0; ntail2 = 0; while (nx % 10L == 0L) { nx = nx / 10L; ntail1++; } while (ny % 10L == 0L) { ny = ny / 10L; ntail2++; } z = nx * ny; sprintf(strZ, "%ld", z); sprintf(strX, "%ld", nx); sprintf(strY, "%ld", ny); n = strlen(strY); strcpy(zeros, "0000000000000000000000000000000000000000"); strcpy(whites, " "); strcpy(bars, "----------------------------------------"); strcpy(loffset, " "); sprintf(line4, "%s%ld", loffset, nx*ny); strncpy(buf, zeros, ntail1 + ntail2); buf[ntail1 + ntail2] = '\0'; strcat(line4, buf); strcpy(line1, loffset); strncpy(buf, whites, strlen(strZ) - strlen(strX)); buf[strlen(strZ) - strlen(strX)] = '\0'; strcat(buf, strX); strcat(line1, buf); strncpy(buf, zeros, ntail1); buf[ntail1] = '\0'; strcat(line1, buf); strcpy(line2, " x ) "); strncpy(buf, whites, strlen(strZ) - strlen(strY)); buf[strlen(strZ) - strlen(strY)] = '\0'; strcat(buf, strY); strcat(line2, buf); strncpy(buf, zeros, ntail2); buf[ntail2] = '\0'; strcat(line2, buf); strcpy(line3, " --"); strncpy(buf, bars, strlen(strZ)); buf[strlen(strZ)] = '\0'; strcat(line3, buf); printf("%s\n", line1); printf("%s\n", line2); printf("%s\n", line3); if (strlen(strY) > 1) { for (i = 0; i < strlen(strY); i++) { buf[0] = strY[strlen(strY) - i - 1]; buf[1] = '\0'; y1 = atoi(buf); if (y1 != 0) { sprintf(strT, "%ld", nx * y1); strcpy(line2, loffset); strncpy(buf, whites, strlen(strZ) - strlen(strT) - i); buf[strlen(strZ) - strlen(strT) - i] = '\0'; strcat(buf, strT); strcat(line2, buf); printf("%s\n", line2); } } printf("%s\n", line3); } printf("%s\n", line4); }




컴파일은 Dev-C++ 개발도구에서 Ctrl+F11 클릭

실행> makeMultTable 230 5100
결과>

          230
   x )   5100
     ------
         23
       115
     ------
       1173000

 

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by Scripter

트랙백 주소 :: http://scripting.tistory.com/trackback/517 관련글 쓰기

댓글을 달아 주세요