关于C语言制作动态库的问题

来源:互联网 发布:莺莺传和西厢记知乎 编辑:程序博客网 时间:2024/06/05 05:52
制作动态库

gcc -fPIC -shared *.c -o libxxxxx.so

example:gcc -fPIC -shared *.c -o libMessage.so

LIBS+=“该库的路径” -lMessage --->编译时找不到库

export LD_LIBRARY_PATH=库的路径 --->运行时找不到库

使用库的方法加载库的路径,连接库名xxxxx

  C++
调用C库函数,需在文件中进行如下修改

example :
#ifdef __cplusplus
extern "C" {
#endif
    int GetTypeOfCPU();//CPU型号
    int GetCoreNUmOfCPU();//CPU核数
    int GetFrequencyOfCPU();//CPU 主频
    float GetVoltageOfCPU(); //CPU电压
    int GetTempOfCPU();    //CPU 温度

    #ifdef __cplusplus
}
    #endif

全局变量声明 扩大变量作用域 ,需在待使用该变量的头文件中重新声明并加上extern 关键字

原创粉丝点击