1

I'm trying to install openCV to Eclipse C++. I installed Opencv and aded the paths and lib files but I get

**** Rebuild of configuration Debug for project test ****

**** Internal Builder is used for build               ****
g++ -IC:\opencv\build\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\main.o    ..\src\main.cpp
g++ -LC:\opencv\build\x86\vc10\lib -LC:\opencv\build\x86\vc11\lib -otest.exe src\main.o -lopencv_core247 -lopencv_core247d -lopencv_highgui247 -lopencv_highgui247d -lopencv_imgproc247 -lopencv_imgproc247d
C:/MinGW/i686-pc-mingw32/lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text+0x3c): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped

I know this question has been asked before but in every one of them the answer was "forgetting to include main() function". But I have a main() function and I still get this error.

Do you have any idea what should I do?

Ege
  • 941
  • 4
  • 17
  • 36

1 Answers1

1

The linker probably is defaulted to use the "Windows" subsystem, which means that the main entry point is not the "main" symbol as you expect it to be, but rather "WinMain".

You can specify the subsystem of your application by passing the following argument at your g++ command line:

-Wl,-subsystem,console

(FYI, for the "Windows" subsystem, you'd use -Wl,-subsystem,windows)

You can also set this in the Eclipse project settings in the linker configuration somwhere I believe.

Basically "console", as the name suggests, creates a console-based application whose default entry-point is the main-function, the other will create a Windows GUI application whose default entry-point is the WinMain-function.

Please give it a try :)

PuerNoctis
  • 1,364
  • 1
  • 15
  • 34
  • 1
    No, a normal main function is completely fine with a Windows subsystem. Any compiler/linker that doesn't accept the normal main function is non-conforming. See [this answer](http://stackoverflow.com/a/5260237/962089). – chris Jan 03 '14 at 18:20
  • @chris You are actually correct, just made a small test. Well, the MSVC itself would be much more strict about it, blasted MS :) – PuerNoctis Jan 03 '14 at 18:25