Windows命令行编译静态动态库的例子

2023-02-10  本文已影响0人  CodingCode
  1. 库源代码
>cat hello.c
#include <stdio.h>

__declspec(dllexport) void hello(void)
{
    puts("I'm Hello");
}
  1. 主程序
>cat main.c
extern void hello(void);

int main(void)
{
    hello();
    return 0;
}
  1. Makefile
>cat Makefile

hello.obj: hello.c
        cl /c hello.c

hello.a: hello.obj
        lib /out:hello.a hello.obj

hello.dll: hello.obj
        link /dll hello.obj

main: hello.a hello.dll
        cl /Femain_staitc.exe main.c hello.a
        cl /Femain_dynamic.exe main.c hello.lib

clean:
        rm *.obj *.a *.lib *.dll *.exp *.exe

注意这里为了区分static library和import library,把静态库命名成.a扩展名。

上一篇 下一篇

猜你喜欢

热点阅读