http://www.swig.org/
SWIG 다운로드
http://www.swig.org/download.html
The Latest Release
The latest development release is swig-1.3.38. View the release notes. Windows users should download swigwin-1.3.38 which includes a prebuilt executable.
파이썬 홈페이지
http://www.python.org/
파이썬 다운로드
http://www.python.org/download/
Download Standard Python Software
For the MD5 checksums and OpenPGP signatures, look at the detailed Python 2.6.1 page:
- Python 2.6.1 compressed source tarball (for Linux, Unix or OS X)
- Python 2.6.1 bzipped source tarball (for Linux, Unix or OS X, more compressed)
- Python 2.6.1 Windows installer (Windows binary -- does not include source)
- Python 2.6.1 Windows AMD64 installer (Windows AMD64 binary -- does not include source)
VC2005 준비 작업
- 테스트 프로젝트 생성
- swig.exe 와 lib 을 테스트 프로젝트로 복사
StdAfx.h 추가 내용
[code c++]
// PYTHON
#ifdef _DEBUG
# undef _DEBUG
# include <python.h>
# define _DEBUG
#else
# include <python.h>
#endif
main.cpp 예제 코드
[code c++]
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize();
PyRun_SimpleString("print('haha')");
Py_Finalize();
return 0;
}
결과
haha
계속하려면 아무 키나 누르십시오 . . .
core.h 파일 추가
[code c++]
#pragma once
void info(const char* msg);
core.cpp 파일 추가
[code c++]
#include "stdafx.h"
#include "core.h"
void info(const char* msg)
{
puts(msg);
}
core.i 파일 추가
%module core
%{
#include "core.h"
%}
%include "core.h"
python_binding.h 파일 추가
[code c++]
#pragma once
void Py_LoadModules();
python_binding.cpp 파일 추가
[code c++]
#include "stdafx.h"
#pragma warning(disable:4996) // 문자열 함수 관련 경고 무시
#include "core_wrap.inc"
void Py_LoadModules()
{
init_core();
}
main.cpp 코드 수정
[code c++]
#include "stdafx.h"
#include "python_binding.h"
int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize();
Py_LoadModules();
PyRun_SimpleString("import core;core.info('ruru')");
Py_Finalize();
return 0;
}
사용자 지정 빌드 단계 구성
1. core.i 오른 클릭 -> 팝업 메뉴/속성 선택
2. core.i 속성 페이지 -> 사용자 지정 빌드 단계 선택
3. 내용 편집
- 명령줄: swig.exe -c++ -python -o $(InputName)_wrap.cpp $(InputPath)
- 설명: swig 인터페이스 파일 생성
- 출력: $(InputName)_wrap.cpp
- 추가 종속성: core.h
MSDN 참고자료:
http://msdn.microsoft.com/ko-kr/library/hefydhhy(VS.80).aspx


python 을 좋아하는 게임 프로그래머