kranthikumar
kranthikumar

Reputation: 215

undefined reference to WinMain Error 1 in eclipse using mingw

**** Build of configuration Debug for project testcase ****

make all 
Building target: testcase.exe
Invoking: MinGW C++ Linker
g++  -o"testcase.exe"  ./atest.o ./main.o  C:/cppunit/src/cppunit/.libs/libcppunit.a 
/mingw/lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
make: *** [testcase.exe] Error 1

undefined reference to `WinMain@16' : mingw/lib/libmingw32.a(main.o):main.c:    
make: *** [testcase.exe] Error 1 

but am using an cpp program. in cpp program which has main.cpp, atestcase.cpp and a.hpp but it showing main.c:(.text+0xd2):

Can any one solve this problem .please can any one help me yours faithfully, r.kranthikumar

Upvotes: 2

Views: 24574

Answers (6)

Sidaray RB
Sidaray RB

Reputation: 1

If it is executable project then Make sure you should have a entry function main() in your project.

Upvotes: 0

Michael Yadidya
Michael Yadidya

Reputation: 1457

I have tried many solutions nothing worked for me.Then I re-created the project and moved the .cpp file to projectname/src/ .

Tested in Eclipse.

Upvotes: 0

Ashish
Ashish

Reputation: 11

Make sure you got main at least. I fixed mine by providing a main function. I didn't have one when I was compiling. I am on windows.. seems by default it is trying to look for winmain.

Upvotes: 1

user153062
user153062

Reputation:

(Is this a duplicate?)

You could keep your main but look up the options

--subsystem,windows -mwindows

in the documentation to your MinGW c++ compiler.

Upvotes: 2

GManNickG
GManNickG

Reputation: 503765

You're building a Windows Application, but you don't have a WinMain that is required by Windows applications.

Likely, you have a main instead. You'll need to either change your project settings (to something along the lines of "Console Application"), or use WinMain instead. You likely want the former.

Note, WinMain is not standard. This is just the Windows linkage requirement.

Upvotes: 2

VonC
VonC

Reputation: 1323115

First, check you did actually save your main.c file (eclipse does not automatically save a source file)

Then, check if your makefile is autogenerated or if you can write it yourself, as in this thread.

CXXFLAGS = -O2 -g -Wall -fmessage-length=0

OBJS =  main.o

LIBS =

TARGET =    say.exe

$(TARGET):  $(OBJS)
    $(CXX) -o $(TARGET) $(OBJS) $(LIBS)

all:    $(TARGET)

clean:
    rm -f $(OBJS) $(TARGET)

Upvotes: 5

Related Questions