2015-08-28 53 views
1

我想加載Python ctypes中的C共享庫。 (linux)在Python ctypes加載共享庫期間的分段錯誤(核心轉儲)

但是它在加載共享庫的過程中產生Segmentation fault (core dumped)

這意味着(如果庫的名稱是A.so

import ctypes 

ctyps.CDLL("A.so") #it makes Segmentation fault 

我想知道的是,通常是什麼問題,如果加載庫時發生Segmentation fault

我不明白它是正常編譯的,我也沒有任何對庫中函數的調用。

加載庫時哪個部分導致此錯誤?

+0

你有沒有['constructor'](https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Function-Attributes.html)函數被'dlopen'調用?有關此操作的示例,請參閱我的答案[此處](http://stackoverflow.com/a/21794318/205580)。 – eryksun

回答

0

在我的情況下,這是templatetype問題在C++方。例如,我用下面的template定義了一個類。

# a.hpp 
template<typename msgType> 
class A{ 
public: 
int get(msgType& msg); 
... 
... 
}; 


#a.cpp 
template<typename msgType> 
int A<msgType>::get(msgType& msg){ 
... 
} 
template int A<std::string>::get(std::string& msg); 

然後,如果我使用A類比std::string等其他類型的地方,它會導致Segmentation fault (core dumped)在加載C++共享庫。