今天將部分工程從靜態(tài)鏈接庫改為動態(tài)鏈接庫,并使用接口方式創(chuàng)建時,原來lua調(diào)用的地方居然掛掉了,掛的地方是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源碼一起封裝在一個靜態(tài)鏈接庫提供給所有程序鏈接使用。有些工程只有1個dll或者exe單獨鏈接,不會出現(xiàn)問題。問題很大程度上就發(fā)生于將一個lua源碼構(gòu)成的庫鏈接給多個dll或者exe,或者混雜鏈接,這樣極易出現(xiàn)莫名其妙的table訪問到dummy_node的錯誤情況
因此,馬上調(diào)整,嘗試將這個庫改為dll。但是在一些模板函數(shù)偏特化上出現(xiàn)了鏈接問題。最后發(fā)現(xiàn),動態(tài)鏈接庫完全就是模板的噩耗,雖然模板函數(shù)是內(nèi)聯(lián),對于全局的模板函數(shù),將其放在頭文件中就會出現(xiàn)多重引用問題。因此放棄,將lua5.1的源碼放在一個dll中,將封裝庫放在靜態(tài)庫中,這樣就絕對沒有任何問題