'사용자 지정 빌드 단계'에 해당되는 글 1건

  1. python vc2005 에서 swig 사용하기 (3) 2009/02/05

python vc2005 에서 swig 사용하기

Posted at 2009/02/05 13:36// Posted in python/pyswig
SWIG 홈페이지
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:



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
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/02/05 13:36 2009/02/05 13:36