二級C技巧(C程序如何使用C++寫好的模塊)
一個用C 寫的程序,如何使用C程序?
1。使用function (args)函數。函數中使用了C 類和其他模塊來實現相應的功能。但是args不包含與C 模塊(類)相關的類型,都是C可以接受的類型,如果需要返廻需要用vector保存的結果,現在考試和大提示都是用char buff[LEN]保存的。
2。定義cFunction(args)接口,與Function完全相同,但需要用C編譯器
extern" C" {
int C function(args){ return function(args);}
}
3。以上全部制作。cpp文件到lib庫中。Libtest.so
4。在C文件裡寫:
Extern int cFunction (args)就可以用了。
注意使用libtest.so庫。gcc xx . c-lxxxxx–ltest
0條評論