LINK:致命错误 LNK1104:无法打开文件 ‘library.lib’

huangapple go评论127阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月12日 19:34:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712841.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定