问题
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
When I add a definition for main(), the library links without issue. What's the deal?
回答1:
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)
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.
来源:https://stackoverflow.com/questions/50848318/msvc-creating-a-static-library-via-makefile