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

坚强是说给别人听的谎言 提交于 2019-12-07 07:35:20

问题


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

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!

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

#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).

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)?

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!


回答1:


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

Look here.

And here.




回答2:


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 wmain function. If it's a Win32 project it was something like WinMain(16), not sure.

I hope it helped.



来源:https://stackoverflow.com/questions/20870676/c-compile-error-lnk1120-and-lnk2019-with-visual-studio

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