2011-05-11 10 views
5

हे सब लोग, मैं एक बहु फ़ाइल प्रोजेक्ट को SWIG करने की कोशिश कर रहा हूं जिसे मैंने VS2010 (C++) में पायथन में बनाया है। मैंने Python26.lib फ़ाइल को लिंक करने में कामयाब रहा है, और मेरे मुख्य .cpp फ़ाइल के लिए एक wrapper .cpp फ़ाइल उत्पन्न करने वाला SWIG है। मैंने एक्सटेंशन के साथ .dll बनाने के लिए अपना कोड सेट किया है .pyd।वीएस -2010 में SWIG कैसे करें?

यह मैं फ़ाइल है मैं वर्तमान में है:

%module HiveGPS 

%{ 
#include "ou_thread.h" 
#include "HiveGPS.h" 
%} 


%include ou_thread.h 
%include HiveGPS.h 

और मैं एक .py और .pyc फ़ाइल पाने के लिए mangaed गए हैं। अब, मेरी .py फ़ाइल चलाने के लिए मेरी समझ से, मुझे इसे अपनी .pyd फ़ाइल से लिंक करने की आवश्यकता है, लेकिन जब मैं ऊपर सूचीबद्ध सेटिंग्स के साथ अपनी परियोजना बनाने के लिए VS2010 का उपयोग करने का प्रयास करता हूं, तो यह एक थ्रेड क्लास I के बारे में शिकायत करता है। 'का उपयोग कर रहा हूँ:

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++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(57): error C4430: missing type specifier - int assumed. Note: C++ does 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++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(64): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(64): warning C4183: 'getName': missing return type; assumed to be a 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++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(98): error C4430: missing type specifier - int assumed. Note: C++ does 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++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(104): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(104): warning C4183: 'getName': missing return type; assumed to be a 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++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(115): error C4430: missing type specifier - int assumed. Note: C++ does 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++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(118): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\*\desktop\hivegps\hivegps\ou_thread.h(118): warning C4183: 'getMessage': missing return type; assumed to be a 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 to recover from 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 ========== 

इन त्रुटियों (ऋण पिछले एक) के सभी मूल रूप से कह रहे हैं कि स्ट्रिंग वर्ग किसी भी तरह से लागू किया जाता है, यह स्ट्रिंग वर्ग के अजगर की परिभाषा के साथ परस्पर विरोधी है? अंतिम त्रुटि थ्रेड क्लास के बारे में शिकायत कर रही है, क्या यह वही समस्या हो सकती है?

उन सभी ने कहा: क्या कोई मुझे बता सकता है कि मैं क्या गलत कर रहा हूं, या बेहतर अभी तक, मुझे वीएस -2010 (एसडब्ल्यूआईजी साइट 2008 के लिए) के लिए ऐसा करने के बारे में एक ट्यूटोरियल पर इंगित करें।

और यदि ऐसा नहीं किया जा सकता है, तो क्या मैं .dll फ़ाइल को किसी भी तरह से .dll फ़ाइल से जेनरेट कर सकता हूं?

लंबे स्पष्टीकरण के लिए खेद है, लेकिन मैं इस पर थोड़ी देर से खो गया हूं इसलिए मैंने सब कुछ समझाने का फैसला किया।

+1

यह कुछ भी हो सकता है। एसडब्ल्यूआईजी काफी हद तक समर्थन करता है, लेकिन कुछ संरचनाओं के साथ मदद की ज़रूरत है। हेडर फाइलों को देखे बिना या आप जेनरेट किए गए एसडब्ल्यूआईजी रैपर को कैसे संकलित कर रहे हैं, यह निर्धारित करना मुश्किल है कि क्या गलत है। –

+0

यदि स्ट्रिंग का उपयोग स्ट्रिंग :: स्ट्रिंग है, तो http://www.swig.org/Doc1.3/Library.html – Torleif

उत्तर

11

ठीक है, मैं बड़ा घूँट और VS2010 उपयोग कर रहा हूँ कोई समस्या नहीं के साथ ...

आपके मामले में, इसे और अधिक की तरह आप को जोड़ने के साथ समस्या है लग रहा है। पुस्तकालयों की जांच से परे, आप 32-64 बिट पुस्तकालयों को जांचना न भूलें जिन्हें आप जोड़ रहे हैं। सभी को x86 लक्ष्य को असफल-सुरक्षित के रूप में लिंक करने का प्रयास करें। और AnyCpu का उपयोग न करें।


VS2010 के तहत बड़ा घूँट का उपयोग कैसे करें।

परिभाषित करता है कि आप mylib.py प्राप्त करना चाहते हैं, इसलिए आपने mylib.i के साथ कुछ मुख्य इंटरफ़ेस फ़ाइलों को "मुख्य" फ़ाइल के रूप में बनाया है। मुझे लगता है कि आपके पास पहले से ही आपके सी ++ कक्षाओं के साथ परियोजना का समाधान है।

(1) सबसे पहले SWIG इंटरफ़ेस के लिए C++ प्रोजेक्ट बनाएं। विज़ुअल सी ++ -> क्लास लाइब्रेरी प्रोजेक्ट का उपयोग करें जो सी ++ डीएलएल स्टब बनाना चाहिए। मैंने वहां सभी आईआई फाइलें रखीं। और .i के रूप में हाइलाइट करने के लिए दृश्य स्टूडियो सेट करें। यह आसान है।

(1,1) परियोजना के लिए mylib_wrap.cxx फ़ाइल जोड़ें (खाली फ़ाइल बनाने, जबकि बड़ा घूँट अभी तक एक जनरेट नहीं की है)

(2)
क) mylib से अधिक प्रेस सही बटन। मैं, गुणों का चयन करें।
बी) आइटम टाइप को "कस्टम बिल्ड टूल" के रूप में सेट करें।
कस्टम निर्माण कदम विंडो में:

echo In order to function correctly, please ensure the following environment variables are 
correctly set: 
echo PYTHON_INCLUDE: %PYTHON_INCLUDE% 
echo PYTHON_LIB: %PYTHON_LIB% 
echo on 
C:\swig\swig.exe -c++ -python %(FullPath) 

परिवर्तन C: \ बड़ा घूँट \ बड़ा घूँट
ग) कमांड लाइन क्षेत्र कुछ की तरह होना चाहिए।अपने पथ पर exe बड़ा घूँट को

घ) आउटपुट क्षेत्र में:

$(InputName)_wrap.cxx 

Custom build window

(3) जाओ इस परियोजना संपत्तियों के लिए:

क) सी ++ टैब - >अतिरिक्त शामिल निर्देशिकाएं
$ (PYTHON_INCLUDE) जोड़ें; ...

ग) लिंकर ->आउटपुट फ़ाइल
पथ-यू-की जरूरत \ _mylib.pyd

घ) लिंकर ->इंक्रीमेंटल लिंकिंग सक्षम
सेट के रूप में (/ INCREMENTAL: नहीं)

ई) लिंकर ->इनपुट ->अतिरिक्त निर्भरता
ऐड $ (PYTHON_LIB); ...

च) C/C++ ->Precompiled हेडर: precompiled हेडर बंद कर दें, सेट ** का उपयोग नहीं कर Precompiled शीर्षलेख * और

जी) सामान्य टैब के बाद stdafx फ़ाइलों को हटा दें। बस की जाँच है कि इन सेट कर रहे हैं:
विन्यास प्रकार = गतिशील लाइब्रेरी (.dll)
चरित्र सेट = उपयोग यूनिकोड वर्ण सेट
साझा भाषा क्रम समर्थन = नहीं साझा भाषा क्रम समर्थन

यह संकलित करता है।

पीएस और अपने सिस्टम में% PYTHON_INCLUDE% और% PYTHON_LIB% चर सेट करने के लिए भी मत भूलना।

+1

आउटपुट होना चाहिए। Cxx फ़ाइल को प्रोजेक्ट में शामिल किया जाना चाहिए? – innochenti

+0

हां। मैंने पोस्ट अपडेट किया। – MajesticRa

0

ऐसा लगता है कि कुछ # शामिल बहिष्कार ou_thread.h में गायब है।

इसके अलावा अधिक, " 'क्लास' प्रकार परिभाषा" संकेत कर सकते हैं कि आप अपने ou_thread.h

यह एक अनुमान लगा रहा है की तरह

#ifndef __ou_thread_h__ 
#define __ou_thread_h__ 

// your stuff, classes, etc. 

#endif 

कुछ भी नहीं है ...