使用 Visual Studio 的 C++ 编译错误(LNK1120 和 LNK2019)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20870676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:22:09  来源:igfitidea点击:

C++ compile error (LNK1120 and LNK2019) with Visual Studio

c++compiler-errorsvisual-studio-2013logitech

提问by ionree

I am a newbie to C++ and I need help with a very basic program.

我是 C++ 的新手,我需要一个非常基本的程序的帮助。

Background information:I recently got the Logitech G19s. It has a small color LCD screen. You can write apps for it in C++. So I decided to try it out, even though I'm new to C++, and write some hello world. Shouldn't be to dificult, but it turns out to be a real pain!

背景信息:我最近拿到了罗技G19s。它有一个小的彩色液晶屏。您可以使用 C++ 为其编写应用程序。所以我决定尝试一下,即使我是 C++ 的新手,并写了一些 hello world。不应该太难,但事实证明这是一个真正的痛苦!

Problem:When I compile my small Hello World app, I get 2 errors: LNK1120 and LNK2019, without any other information. Here's my code:

问题:当我编译我的小型 Hello World 应用程序时,我收到 2 个错误:LNK1120 和 LNK2019,没有任何其他信息。这是我的代码:

#pragma comment(lib, "LogitechLcd.lib")
#include "LogitechLcd.h"

int main() {
    LogiLcdInit(L"Hello World", LOGI_LCD_TYPE_COLOR);
    while (true) {
        LogiLcdUpdate();
        LogiLcdColorSetText(4, L"Hello G19s", 255, 0, 0);
    }
    LogiLcdShutdown();
    return 0;
}

and here's the LogitechLcd.h (pastebin.com).

这是LogitechLcd.h (pastebin.com)

When I compile this (with Visual Studio Professional 2013), I get the errors mentioned above. Can anyone help me out (and, if possible, explain why it doesn't work)?

当我编译这个(使用 Visual Studio Professional 2013)时,我得到了上面提到的错误。任何人都可以帮助我(并且,如果可能,请解释为什么它不起作用)?

EDIT:I somewhat got it to work now! Viusal Studio didn't find the lib, so I had to place it in the project folder. Very stupid mistake!

编辑:我现在有点让它工作了!Viusal Studio 没有找到这个库,所以我不得不把它放在项目文件夹中。非常愚蠢的错误!

采纳答案by FuzzyBunnySlippers

It sounds like you have the project set up as the wrong type.

听起来您将项目设置为错误的类型。

Look here.

这里

And here.

这里

回答by Toucan Sign

Is it a console project? (If you don't know, look at Project Properties> Linker> System> Subsystem). It should be the first thing that comes up. If so, make your main function a wmainfunction. If it's a Win32 project it was something like WinMain(16), not sure.

它是一个控制台项目吗?(如果您不知道,请查看Project Properties> Linker> System> Subsystem)。它应该是出现的第一件事。如果是这样,请将您的主函数设为wmain函数。如果它是一个 Win32 项目,它类似于WinMain(16),不确定。

I hope it helped.

我希望它有所帮助。