今天將部分工程從靜態鏈接庫改為動態鏈接庫,并使用接口方式創建時,原來lua調用的地方居然掛掉了,掛的地方是table在清除時,crash在newkey
google了一下,找到了一篇頗有參考價值的文章
A common error is to link C extension modules (shared libraries)
with the static library. The linker command line for extension
modules must not ever contain -llua or anything similar!
I.e. check your build process. If you are unsure where the two
copies of the Lua core come from, grep the binaries for some
characteristic error message, like "table index is nil".
我的lua封裝庫是與lua源碼一起封裝在一個靜態鏈接庫提供給所有程序鏈接使用。有些工程只有1個dll或者exe單獨鏈接,不會出現問題。問題很大程度上就發生于將一個lua源碼構成的庫鏈接給多個dll或者exe,或者混雜鏈接,這樣極易出現莫名其妙的table訪問到dummy_node的錯誤情況
因此,馬上調整,嘗試將這個庫改為dll。但是在一些模板函數偏特化上出現了鏈接問題。最后發現,動態鏈接庫完全就是模板的噩耗,雖然模板函數是內聯,對于全局的模板函數,將其放在頭文件中就會出現多重引用問題。因此放棄,將lua5.1的源碼放在一個dll中,將封裝庫放在靜態庫中,這樣就絕對沒有任何問題