How to compile a 32-bit binary by using 64-bit gcc

64비트 mingw gcc 컴파일러로 32비트 바이너리 생성시에는…
컴파일 타임이나.. 링크 타임시에.. -m32 옵션을 붙임.

$ gcc -m32 -c hello.c
$ objdump -p hello.o
hello.o:     file format pe-i386

$ gcc hello.c
$ file hello.exe
hello.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

-m32 옵션을 붙이지 않으면 당연히 64비트 바이너리 생성.

$ gcc -c hello.c
$ objdump -p hello.o
hello.o:     file format pe-x86-64

$ gcc hello.c
$ file hello.exe
hello.exe:  PE32+ executable for MS Windows (console) Mono/.Net assembly

PE32 는 32bit executable file, PE32+ 는 64bit executable file에 대한 규악.

 

base64

base64.c
base64.h

간단한 예제를 만들어 보면..

// ----- base64 encoding
char *in = "abcd";
size_t inlen = strlen(in);
char *out;
base64_encode_alloc(in, inlen, &out);
printf("%s", out);
free(out);
free(in);

// ------- base64 decoding

char *in = "base64 인코딩 된 스트링..";
size_t inlen = strlen(in);
char *out;
size_t outlen;
base64_decode_alloc(in, inlen, &out, &outlen);
printf("%s", out);
free(out);
free(in);
 

GNU ASM 64비트 포팅 가이드

http://www.x86-64.org/documentation/assembly.html

 

VIM 기본 셋팅

vim을 설치하고서 항상 셋팅하는 기본 정보.

set nobackup
set ts=4
set sw=4

:colors darkblue

set guifont=Bitstream_Vera_Sans_Mono:h10:cHANGEUL

BitstreamVeraSansMono_malgun.zip

 

Image Processing 강의 자료

Image Processing 강의 자료.
VC++로 구현하는 방법도 들어있음.

image_processing.zip

출처: http://dasan.sejong.ac.kr/~hmoon/lecture.html

 

Gang Garrison 2

솔닷 느낌의.. 게임.

다운로드: http://www.ganggarrison.com/

 

한 지점을 기준으로 라인 회전 시키기

//**************************************************************
// Rotate a line around a center point by an angle theta
// IN: ref Array of 4 doubles for (x1,y1) to (x2,y2) line
//    center point (cx,cy)
//    Rotation angle theta in Rad
//    pass in 32bit color if you want to add a draw line call
//***************************************************************************
void RotateLine2 (double center[2], double (&line)[4],double theta, Uint32 color)
{
	double length = 0.0;
	double cx_x1,cy_y1,cx_x2,cy_y2;

	cx_x1 = line[0] - center[0];
	cy_y1 = line[1] - center[1];
	cx_x2 = line[2] - center[0];
	cy_y2 = line[3] - center[1];

    line[0]= center[0] - ((int)(cx_x1*cos(theta)))-((int)(cy_y1* sin(theta)));
    line[1]= center[1] - ((int)(cx_x1*sin(theta)))+((int)(cy_y1* cos(theta))); 

    line[2]= center[0] - ((int)(cx_x2*cos(theta)))-((int)(cy_y2* sin(theta)));
    line[3]= center[1] - ((int)(cx_x2*sin(theta)))+((int)(cy_y2* cos(theta)));
}
 

두 라인의 교차지점 구하기

참고: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/

bool calc_intersection(
    float ax, float ay, float bx, float by,
    float cx, float cy, float dx, float dy,
    float* x, float* y)
{
    float num = (ay-cy) * (dx-cx) - (ax-cx) * (dy-cy);
    float den = (bx-ax) * (dy-cy) - (by-ay) * (dx-cx);
    if(fc::Math<float>::FAbs(den) < Math<float>::intersection_epsilon) return false;
    float r = num / den;
    *x = ax + r * (bx-ax);
    *y = ay + r * (by-ay);
    return true;
}
 

sed 를 이용한 newline 제거

음.. newline 으로 구분되어진 데이타가 있는데..
이걸 vector 연산을 하기위해.. newline 대신에 “,” 로 대체할때.. 아래와 같이 함.

$ sed ':a;N;$!ba;s/\n/,/g'
 

NSIS 확장자 연결

우선.. 아래의 헤더파일을 다운로드 받고.

http://nsis.sourceforge.net/FileAssoc

스크립트에서는 아래와 같이 함.

확장자 연결시..

	!insertmacro APP_ASSOCIATE "mtp" "mytcl.projectfile" "MyTcl Project File" "$INSTDIR\mytcl.exe,0" \
		"Open with MyTcl" "$INSTDIR\mytcl.exe $\"%1$\""
	!insertmacro APP_ASSOCIATE "tcl" "mytcl.tclfile" "Tcl File" "$INSTDIR\mytcl.exe,0" \
		"Edit with MyTcl" "$INSTDIR\mytcl.exe $\"%1$\""
	!insertmacro UPDATEFILEASSOC

확장자 제거시..

	!insertmacro APP_UNASSOCIATE "mtp" "mytcl.projectfile"
	!insertmacro APP_UNASSOCIATE "tcl" "mytcl.tclfile"
	!insertmacro UPDATEFILEASSOC