请问在linux中C语言是否可以调用QT生成的动态链接库?
如何可以调用该怎么实现?

解决方案 »

  1.   

    動態鏈接庫就是有統一標準的,都可以調用。編譯時聲明函數,運行時指定LD_LIBRARY_PATH。
      

  2.   

    可以,写个 hello world 测试一下就知道了
      

  3.   

    C++编写的动态库函数名称及使用模型跟c的不太一样,最好将c++功能封装层c调用接口进行使用,否则c++ 的很多特性(RAII, exception等)会被破坏,引起不必要的错误.
    简单弄个例子:
    C++
    class A{
    public:
        A(){}
        ~A(){}
    void show(){}
    };
    //C code
    #ifdef __cplusplus
    extern "C" {
    #endif // __cplusplus
    void* A_new() {
             return new A();
    }
    void A_show(void* a) {
           a->show();
    }
    void A_destroy(void* a) {
          delete a;
    }
    #ifdef __cplusplus
    }
    #endif // __cplusplus
      

  4.   

    忘了填类型转换了,void* a 需要指针转换成A*, 
    reinterpret_cast<A*>(a)->show();
    delete reinterpret_cast<A*>(a);
      

  5.   


    应不行吧, qt里是使用c++语言的。c++可以兼容c, 但 c应兼容不了c++.
    在qt里使用c的动态库没问题.