英文:
LINK : fatal error LNK1104: cannot open file 'library.lib'
问题
以下是已翻译的内容:
My original source code is a more complex, but I reduced it to one header.hxx and one impl.cxx file, because It's a question about MS Visual Studio link.exe.
I wrote a batch for a static library building. Here are the commands I used:
call "c:\Program Files (x86)\Microsoft Visual Studio19\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64 10.0.22621.0
cl /c /EHsc /nologo /W3 /D "_DEBUG" impl.cxx
link /OUT:"library.lib" /DEBUG /SUBSYSTEM:CONSOLE /NOLOGO /MACHINE:X64 impl.obj
The compilation works fine, but the linker shows this error:
Creating library library.lib and object library.exp
LINK : fatal error LNK1104: cannot open file 'library.lib'
What is wrong/missing in my commandline calls?
Here is the source code:
header.hxx
#pragma once
extern __declspec(dllexport) int abc1();
impl.cxx
#include "header.hxx";
extern __declspec(dllexport) int abc1()
{
return 0;
}
英文:
My original source code is a more complex, but I reduced it to one header.hxx and one impl.cxx file, because It's a question about MS Visual Studio link.exe.
I wrote a batch for a static library building. Here are the commands I used:
call "c:\Program Files (x86)\Microsoft Visual Studio19\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64 10.0.22621.0
cl /c /EHsc /nologo /W3 /D "_DEBUG" impl.cxx
link /OUT:"library.lib" /DEBUG /SUBSYSTEM:CONSOLE /NOLOGO /MACHINE:X64 impl.obj
The compilation works fine, but the linker shows this error:
Creating library library.lib and object library.exp
LINK : fatal error LNK1104: cannot open file 'library.lib'
What is wrong/missing in my commandline calls?
Here is the source code:
header.hxx
#pragma once
extern __declspec(dllexport) int abc1();
impl.cxx
#include "header.hxx"
extern __declspec(dllexport) int abc1()
{
return 0;
}
答案1
得分: 0
我使用了错误的工具。我应该使用 lib.exe(https://learn.microsoft.com/en-us/cpp/build/reference/overview-of-lib?view=msvc-170) 而不是 link.exe。
请看 John 的评论。
非常感谢 John。
英文:
I was using wrong tool. I was supposed to use lib.exe (https://learn.microsoft.com/en-us/cpp/build/reference/overview-of-lib?view=msvc-170) instead of link.exe.
See the comments of John.
Thanks a lot John.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论