2014-04-04 2 views
2

소스가없는 헤더 파일이있는 Linux .so-library secdyn.so가 있습니다.파이썬에 C++ 줄 바꿈 - 코드의 일부가 소스가없는 공유 라이브러리 인 경우

/* secdyn.h */ 
int sec2(int a); 

나는 이렇게 내가

#include <iostream> 
#include "secdyn.h" 
int subdyn(int a,int debuglevel); 

과 subdyn.cpp

#include "subdyn.h" 
int subdyn(int a,int debuglevel) 
{ 
    if (debuglevel>0) std::cout << "a = " << a << std::endl; 
    return sec2(a); 
} 

과 subdyn.i (참조하십시오 subdyn.h 쓰기, 꿀꺽 꿀꺽 통해 파이썬이 포장 할 아래에서 내 대답 !!! -이 첫 줄의 오류)

%module substatic 
%{ 
    #define SWIG_FILE_WITH_INIT 
    #include "subdyn.h" 
%} 
%include "subdyn.h" 

와이 빌드 내가

$ ldd _subdyn.so 
linux-gate.so.1 => (0xb7702000) 
secdyn.so => ./secdyn.so (0xb76f4000) 
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb75ee000) 
libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xb75c7000) 
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb75aa000) 
libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb7446000) 
/lib/ld-linux.so.2 (0xb7703000) 

내가 secdyn.so과 subdyn.so 사용하는 C++ 바이너리 할 수있다 "PWD"은 다음을 포함 $의 LD_LIBRARY_PATH를 설정

swig -c++ -python subdyn.i 
g++ -fPIC subdyn_wrap.cxx -c -g -I/usr/include/python2.7/ 
g++ -fPIC subdyn.cpp -c -g 
g++ -shared subdyn_wrap.o subdyn.o secdyn.so -o _subdyn.so 

컴파일 - 잘 작동합니다.

그러나 나는이 휴식을 파이썬

$ python 
>>> import subdyn 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: dynamic module does not define init function (initsubdyn) 

secdyn 정적 libary로 오면 나는 모든 것이 잘 작동주의 수에이 라이브러리를 가져올 수 있지만, 동적 라이브러리 수 없습니다.

나는 작동하는 정적 꿀꺽 꿀꺽 링크 exampe 및 http://petertoft.dk/code/swig.tgz

단서에서 작동하지 않는 동적 링크 예 (위의 코드)를 첨부?

+0

기호를 내 보내야합니다. –

+0

어떻게하면됩니까? Thanx Karoly –

+0

게시물에 오자가 있다고 생각합니다.'ldd subdyn.so'는'ldd _subdyn.so'이어야합니까? +1 솔루션을 찾고 게시! – Schollii

답변

2

내가 놓친 버그는 잘못되어있는 subdyn.i입니다. 첫 번째 줄은 % 모듈 subdyn을 읽어야합니다.

그러면 작동합니다. http://petertoft.dk/code/swig.tgz을 다시 업로드했습니다. 정적 및 동적 예가 포함되어 있습니다. 이제 모두 작동합니다.