MSVC - Creating a static library via Makefile

喜夏-厌秋 提交于 2021-01-27 21:31:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!