MinGW gcc使用知识积累

1,编译test.c文件:

2,动态链接库编译:

    1. 动态链接库文件
      //dlltest.c
    2. int Double(int x)
    3. {
    4. return x * 2;
    5. }
       
       
      编译命令gcc dlltest.c -shared -o dlltest.dll -Wl,--out-implib,dlltest.lib
      其中 -shared 告诉gcc dlltest.c 文件需要编译成动态链接库。-Wl 表示后面的内容是ld 的参数,需要传递给 ld。 --out-implib,dlltest.lib 表示让ld 生成一个名为 dlltest.lib 的导入库。

      如果还需要 .def 文件,则上面的命令行可以写为:

      gcc dlltest.c -shared -o dlltest.dll -Wl,--output-def,dlltest.def,--out-implib,dlltest.a
      ---------------------
      作者:liyuanbhu
      来源:CSDN
      原文:https://blog.csdn.net/liyuanbhu/article/details/42612365
      版权声明:本文为博主原创文章,转载请附上博文链接!
       
       
      1. 使用动态链接库的文件
        //main.c
      2. #include <stdio.h>
      3. int Double(int x);
      4. int main(void)
      5. {
      6. printf("Hello :%d\n", Double(333));
      7. return 0;
      8. }
      编译命令 :gcc main.c dlltest.lib -o main.exe 其中 -o表示输出文件 o==out
       

posted on 2019-04-03 20:11  杜鹃醉鱼鱼  阅读(166)  评论(0编辑  收藏  举报

导航