作者asd24693120 (曙光)
看板Python
標題[問題] linux呼叫so函式,執行出現undefined s..
時間Tue Feb 16 00:28:19 2021
各位前輩好,目前遇到了一個問題,在建置so library檔時,呼叫內部函式出現了undefi
ned symbol,目前完全不知道解決的方向,希望各位前輩能夠指導
https://i.imgur.com/7yepT73.jpg
這是我的程式碼
https://glot.io/snippets/fvwlmsu43t
這是123.py的程式碼
https://glot.io/snippets/fvwz2xprsu
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.225.58.19 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1613406501.A.169.html
1F:→ oToToT: 你的.so怎麼生的?02/16 00:36
https://glot.io/snippets/fvwlmsu43t
我是使用makefile產生的,這是我的程式碼
※ 編輯: asd24693120 (36.225.58.19 臺灣), 02/16/2021 01:05:40
※ 編輯: asd24693120 (36.225.58.19 臺灣), 02/16/2021 01:06:28
2F:→ zerof: 不用 include Python.h?02/16 05:21
3F:→ zerof: 你如果只有要用幾個 function 的話參考 ctypes 看看02/16 05:51
因為不只用到幾個function,所以可能不能用,之前我就有試過ctypes
4F:推 Falldog: 1. 沒有link到完整的lib 2. python不能直接call C++ func02/17 11:16
5F:→ Falldog: 需要用extern "C" {} 的方式宣告 function02/17 11:18
有的,我有加上exten c了,但結果仍然是symbol undefined
https://i.imgur.com/XVBXopg.jpg
※ 編輯: asd24693120 (118.169.185.235 臺灣), 02/19/2021 11:33:40
※ 編輯: asd24693120 (118.169.185.235 臺灣), 02/19/2021 11:35:29
6F:→ zerof: header & cpp 裡面只看到兩個 functions 所以才說你如果只02/20 02:31
7F:→ zerof: 有幾個的話可以考慮用 ctypes (另外在 code 裡面沒看到 squ02/20 02:31
8F:→ zerof: are 的 definition, 不過我 cpp 不熟也不太確定這樣有沒有02/20 02:31
9F:→ zerof: 問題...)02/20 02:31
Z大您好,那想請問我如果要再試試ctypes要參考哪一篇文章呢?因為我之前有參考過幾
篇,但因為他們對於加extern c的位置解釋的模糊不清,因此也有可能是我理解錯意思,
希望z大能夠指導,我能私下寄信給您嗎?
※ 編輯: asd24693120 (111.250.156.31 臺灣), 02/20/2021 16:37:07