MyAlbum   Pet
DirectX   openGL   Java   C/C++   STL   C#   Python   Window   ActiveX   SE & Refactoring   Game   Unicode   googleDesktop   Network   Database   Web   php   asp   asp.net   Library   QT   wxWidget   Something to read  
ToDo
zelon's WebAlbum
Google Tools
Google Naver map
ToRearrange
OpenOffice.org
Eclipse
Check W3 validator
linux Programming
e i R f
Anonymous

Contents

1 배포하기
2 프로그래밍 팩키지
3 텍스트 기반 개발툴
4 gcc 3.4 부터 있는 precompiled header 사용방법
5 gdb 의 사용
6 make
7 컴파일 빠르게 하기
7.1 ccache
8 외부 프로그램 실행 후 stdout, stderr 받아오기
9 시스템 호출 감시하기

1 배포하기 #


2 프로그래밍 팩키지 #


  • manpages-dev
  • boost-dev
  • libstdc-dev

3 텍스트 기반 개발툴 #


4 gcc 3.4 부터 있는 precompiled header 사용방법 #


-. 먼저 원하는 헤더 파일들을 모아서 stdafx.h 라는 파일을 하나 만든다. -. 이 파일 안에 주로 쓰지만 변경하지않는(vector, list, iostream 등) 헤더 파일들을 넣는다. -. 이 stdafx.h 헤더 파일을 컴파일 시켜놓는다.

아래는 cpp 의 경우,
g++ -x c++-header stdafx.h -o stdafx.h.gch

아래는 c 의 경우,
gcc -x c-header stdafx.h -o stdafx.h.gch

-. 위와 같이 컴파일을 하면 꽤 큰 용량의 stdafx.h.gch 파일이 생긴다. 이 파일이 precompiled header 이다.

-. precompiled header 를 쓰기 위해서는 원하는 곳에 #include "stdafx.h" 를 추가하는 것으로 끝난다. 즉 stdafx.h 파일이 있는 곳에 stdafx.h.gch 가 있으면 gch 를 먼저 본다는 것이다(제가 영어 해석하기에 그랬습니다 :D) -. gch 를 이용하면 컴파일이 무척 빠르다.



아래는 제가 테스트 해본 방법입니다.

"stdafx.h" 파일
#include <iostream>
#include <vector>

"usePCH.cpp" 파일
#include "stdafx.h"

using namespace std;

int main()
{
  vector < int > v;
  v.push_back(1);

  cout << "ok" << endl;
}

"notPCH.cpp" 파일
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  vector < int > v;
  v.push_back(1);

  cout << "ok" << endl;
}

먼저 stdafx.h 파일을 -x 옵션을 이용해서 stdafx.h.gch 파일을 만들어 낸 후, usePCH.cpp 파일과 notPCH.cpp 파일을 둘다 g++ [filename] 으로 컴파일해보았습니다.

정확한 시간을 잴 필요도 없이 체감속도가 달랐습니다. usePCH.cpp 가 훨씬 빠르더군요. 그리고 stdafx.h 에 포함된 헤더 파일이 많을 수록 훨씬 체감 속도가 차이가 납니다. 괜히 stl의 이런저런 헤더파일들을 쓰게 하면 훤씬 속도 차이가 많이 나겠죠.


5 gdb 의 사용 #


  • gdb GDB 의 사용

6 make #


7 컴파일 빠르게 하기 #


7.1 ccache #

  • http://ccache.samba.org/
  • gcc 나 g++ 앞에 ccache 를 붙이기만 하면 된다.

  • 8 외부 프로그램 실행 후 stdout, stderr 받아오기 #

    
    void test()
    {
    	int pipeDes[2], pipeDesErr[2];
    	
    	if ( pipe(pipeDes) == -1 || pipe(pipeDesErr) == -1 )
    	{
    		cout << "pipe create failed" << endl;
    		return;
    	}
    	
    	
    	int childPID = fork();
    	
    	/// 0 이면 자식프로세
    	if ( childPID == 0 )
    	{
    		cout << "child process" << endl;
    		dup2(pipeDes[1], 1);
    		dup2(pipeDesErr[1], 2);
    		close(pipeDes[0]);
    		close(pipeDes[1]);
    		close(pipeDesErr[0]);
    		close(pipeDesErr[1]);
    		
    		execl("./test", "./test", "", (char*)0);
    		exit(0);
    	}
    	else if ( childPID > 0 )
    	{
    		cout << "parent process" << endl;
    		
    		/*
    		int secondChildPID = fork();
    		
    		if ( secondChildPID == 0 )
    		{
    			cout << "second child process" << endl;
    			dup2(pipeDesErr[0], 0);
    			close(pipeDes[0]);
    			close(pipeDes[1]);
    			close(pipeDesErr[0]);
    			close(pipeDesErr[1]);
    			
    		}
    		*/
    		
    		close(pipeDes[1]);
    		close(pipeDesErr[1]);
    		
    		
    		cout << "|start|" << endl;
    		stringstream strSTDOUT, strSTDERR;
    		while ( true )
    		{
    			char szBuff[1024] = { 0 };
    			int ret = read(pipeDes[0], szBuff, sizeof(szBuff));
    			
    			if ( ret <= 0 ) break;
    			
    			cout << szBuff << endl;
    			
    		}
    		
    		while ( true )
    		{
    			char szBuff[1024] = { 0 };
    			int ret = read(pipeDesErr[0], szBuff, sizeof(szBuff));
    			
    			if ( ret <= 0 ) break;
    			
    			cout << szBuff << endl;
    			
    		}
    		cout << "|end|" << endl;
    	}
    }
    
    


    9 시스템 호출 감시하기 #


    strace 를 이용하면 이 프로그램이 어떤 시스템 함수들을 호출하는지 알 수 있다
    strace ./a.out