-1

I am getting an error when trying to compile some C++ code:

#include "graphics.h"

HDC hdc;
int main()
{


    initwindow(400, 300);

    for (int i = 0; i < 300; i++) {
        Rectangle(hdc, 100 + i, 100, 300, 300);
    }
    getch();

}

Not sure if the graphics.h file is in the right place, stupidly on desktop.

Also, this come up as error:

unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Not sure what you mean by "stupidly on desktop"; where else would you do C++ development? Since you're using `"graphics.h"` it is looking for the header file where your C++ code is. – Elliott Frisch Jun 23 '22 at 23:33
  • Where are you getting the graphics.h file you are using from? – Avi Berger Jun 23 '22 at 23:42
  • https://github.com/SagarGaniga/Graphics-Library/blob/master/graphics.h – Transformers Jun 23 '22 at 23:44
  • 1
    Sounds like you don't have the winBGI library to go with graphics.h. You'll also need a GCC3 compiler to build it and Windows XP to run it on. Say, [can I talk you into using something a couple decades more up to date?](https://sdl-bgi.sourceforge.io/) – user4581301 Jun 23 '22 at 23:51
  • No winBGI library – Transformers Jun 23 '22 at 23:52
  • graphics.h is the interface header for the BGI library. You need to have the library to go with the header. The problem is the library is an antique from the 1980s and the port of it the header you've got came from dates to around 2005 (The year Transformers the Movie takes place in. Ha!) that doesn't run particularly well on a modern computer. Unless you have a Pentium from the early 2000s running Windows XP, you can do everything right and it probably still won't work. – user4581301 Jun 23 '22 at 23:54
  • 1
    Unless you have to use BGI for school, I recommend learning the graphics tools in [SDL](https://www.libsdl.org/) or [SFML](https://www.sfml-dev.org/) because they are much closer to the tools you'll find yourself using today. – user4581301 Jun 23 '22 at 23:59

1 Answers1

0

You've set the project to build as a Windows application, not a command line application. Change int main() to:

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx

Or, change your project properties to be a command line application.

NewbieDeveloper
  • 408
  • 1
  • 10