MSVC-通过Makefile创建静态库 [英] MSVC - Creating a static library via Makefile
问题描述
因此,我一直试图通过在Microsoft x64命令行工具下启动mingw32-make在MSVC下在Windows下创建静态库.我收到链接器错误LNK1561:必须定义入口点.为了完整起见,这是我的Makefile.
So I've been trying to create a static library under Windows under MSVC by launching mingw32-make under Microsoft's x64 Command Line Tools. I get linker error LNK1561: entry point must be defined. For completeness, here's my Makefile.
all: build\lib\libds.lib
build\lib\libds.lib: build\obj\priority-queue.obj
link /OUT:build\bin\libds.lib build\obj\priority-queue.obj
build\obj\priority-queue.obj: libs/ds/priority-queue.c include/ds/priority-queue.h
cl /Iinclude /c libs/ds/priority-queue.c /Fo:build\obj\priority-queue.obj
当我为main()添加定义时,库链接没有问题.怎么了?
When I add a definition for main(), the library links without issue. What's the deal?
推荐答案
在构建静态库时,我们需要使用 link.exe/lib [LIB选项]
或 link.exe -lib[LIB选项]
或 lib [LIB选项]
.这没有很好的记录(部分在这里- 正在运行的LIB )
when we build static library we need use link.exe /lib [LIB Options]
or link.exe -lib [LIB Options]
or lib [LIB Options]
. this is not well documented (partially here - Running LIB)
请注意-当您运行 lib.exe xxx
时-它会执行 link.exe -lib xxx
并退出-因此 lib.exe
不是自助服务实用程序,而是填充 link.exe
(与 dump.exe xxx
重新执行 link.exe -dump xxx
相同).我们当然可以使用 lib.exe
进行构建,但是最好使用 link.exe/lib
命令.
note - that when you run lib.exe xxx
- it exec link.exe -lib xxx
and exit - so lib.exe
not self-service utility but shim to link.exe
(same as dump.exe xxx
reexec link.exe -dump xxx
). we of course can use lib.exe
for build, but better use link.exe /lib
command.
这篇关于MSVC-通过Makefile创建静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!