c++ - How to SWIG in VS2010? -


hey everybody, i'm trying swig multi file project made in vs2010 (c++) python. i've managed link python26.lib file, , have swig generating wrapper .cpp file main .cpp file. i've set code build .dll extension .pyd.

this .i file have currently:

%module hivegps  %{ #include "ou_thread.h" #include "hivegps.h" %}   %include ou_thread.h %include hivegps.h 

and i've mangaed .py , .pyc file. now, understanding in order run .py file, need link .pyd file, when try use vs2010 build project settings listed above, complains thread class i'm using:

1>------ build started: project: hivegps, configuration: release win32 ------ 1>build started 5/11/2011 1:41:30 pm. 1>initializebuildstatus: 1>  touching "release\hivegps.unsuccessfulbuild". 1>clcompile: 1>  hivegps_wrap.cpp 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(57): error c2146: syntax error : missing ';' before identifier 'm_strname' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(57): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(57): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(64): error c2146: syntax error : missing ';' before identifier 'getname' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(64): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(64): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(64): warning c4183: 'getname': missing return type; assumed member function returning 'int' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(98): error c2146: syntax error : missing ';' before identifier 'm_strname' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(98): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(98): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(104): error c2146: syntax error : missing ';' before identifier 'getname' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(104): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(104): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(104): warning c4183: 'getname': missing return type; assumed member function returning 'int' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(115): error c2146: syntax error : missing ';' before identifier 'msg' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(115): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(115): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(118): error c2146: syntax error : missing ';' before identifier 'getmessage' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(118): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(118): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(118): warning c4183: 'getmessage': missing return type; assumed member function returning 'int' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(51): error c2011: 'openutils::thread' : 'class' type redefinition 1>          c:\users\*\desktop\hivegps\hivegps\ou_thread.h(51) : see declaration of 'openutils::thread' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(93): error c2011: 'openutils::mutex' : 'class' type redefinition 1>          c:\users\*\desktop\hivegps\hivegps\ou_thread.h(93) : see declaration of 'openutils::mutex' 1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(113): error c2011: 'openutils::threadexception' : 'class' type redefinition 1>          c:\users\*\desktop\hivegps\hivegps\ou_thread.h(113) : see declaration of 'openutils::threadexception' 1>c:\users\*\desktop\hivegps\hivegps\hivegps.h(29): error c2504: 'openutils::thread' : base class undefined 1>c:\users\*\desktop\hivegps\hivegps\hivegps.h(53): error c2079: 'hivegps::readwritemutex' uses undefined class 'openutils::mutex' 1>hivegps_wrap.cpp(3086): error c2027: use of undefined type 'openutils::thread' 1>          c:\users\*\desktop\hivegps\hivegps\ou_thread.h(51) : see declaration of 'openutils::thread' 1>hivegps_wrap.cpp(3086): fatal error c1903: unable recover previous error(s); stopping compilation 1> 1>build failed. 1> 1>time elapsed 00:00:02.10 ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

all of these errors (minus last one) saying string class implemented somehow, conflicting python's definition of string class? last error complaining thread class, same problem?

all of said: can tell me i'm doing wrong, or better yet, point me tutorial of how vs2010 (the swig site 2008).

and if can't done, can link .py file have generated .dll file somehow?

sorry long explanation i'm kinda lost on 1 decided explain everything.

ok, i'm using swig , vs2010 no problems...

in case, looks more have problems linking. beyond check of libraries, dont forget check 32-64 bit libraries linking. try link x86 target fail-safe. , don't use anycpu.


how use swig under vs2010.

lets define want obtain mylib.py, created swig interface files mylib.i "main" file. assume have solution project c++ classes there.

(1) first create c++ project swig interface. use visual c++->class library project should create c++ dll stub. put .i files there. , set visual studio highlight .i .h - handy.

(1.1) add mylib_wrap.cxx file project (create empty file while swig hasn't generated 1 yet)

(2)
a) press right button on mylib.i, choose properties.
b) set itemtype "custom build tool".
in custom build step window:
c) command line field should like:

echo in order function correctly, please ensure following environment variables correctly set:  echo python_include: %python_include%  echo python_lib: %python_lib%  echo on  c:\swig\swig.exe -c++ -python %(fullpath)  

change c:\swig\swig.exe path swig

d) in outputs field:

$(inputname)_wrap.cxx 

custom build window

(3) go project properties:

a) c++ tab -> additional include directories
add $(python_include); ...

c) linker -> output file
path-you-needed\_mylib.pyd

d) linker -> enable incremental linking
set no (/incremental:no)

e) linker -> input -> additional dependencies
add $(python_lib);...

f) c/c++ -> precompiled headers: switch off precompiled headers, set **not using precompiled headers* , remove stdafx files after

g) general tab. check these set:
configuration type = dynamic library (.dll)
character set = use unicode character set
common language runtime support = no common language runtime support

it compiles.

p.s. , dont forget set %python_include% , %python_lib% variables in system too.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -