Windows 下 Clang 静态编译 Exe 参数详解
在 Windows 下使用 Clang 进行静态编译,需要添加静态链接库参数,具体如下:
-
编译器参数:'-static',表示链接静态库
-
静态库参数:
- '-l' 参数,表示链接静态库,后面跟上库名,例如 '-lpthread'
- '-L' 参数,表示指定静态库的搜索路径,后面跟上库的路径,例如 '-L/usr/local/lib'
例如,编译一个 hello.c 程序,并链接 libpthread 静态库,命令如下:
clang -static -o hello hello.c -lpthread -L/usr/local/lib
这条命令将会编译 hello.c 程序,并链接 libpthread 静态库,生成可执行文件 hello。其中 '-L' 参数指定了 libpthread 库的搜索路径为 /usr/local/lib。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/oejv 著作权归作者所有。请勿转载和采集!