使用 mingw 在 Eclipse 中对 WinMain 错误 1 的未定义引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2040730/
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
undefined reference to WinMain Error 1 in eclipse using mingw
提问by kranthikumar
**** 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):
但我正在使用 cpp 程序。在具有 main.cpp、atestcase.cpp 和 a.hpp 但它显示 main.c:(.text+0xd2) 的 cpp 程序中:
Can any one solve this problem .please can any one help me yours faithfully, r.kranthikumar
任何人都可以解决这个问题。请任何人忠实地帮助我,r.kranthikumar
回答by VonC
First, check you did actually saveyour main.c
file(eclipse does not automatically save a source file)
首先,检查您是否确实保存了main.c
文件(eclipse 不会自动保存源文件)
Then, check if your makefile is autogenerated or if you can write it yourself, as in this thread.
然后,检查您的 makefile 是否是自动生成的,或者您是否可以自己编写,就像在这个线程中一样。
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)
回答by GManNickG
You're building a Windows Application, but you don't have a WinMain
that is required by Windows applications.
您正在构建Windows Application,但您没有WinMain
Windows 应用程序所需的。
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.
很可能,你有一个main
。您需要更改您的项目设置(更改为类似于“控制台应用程序”的内容),或者WinMain
改为使用。你可能想要前者。
Note, WinMain
is not standard. This is just the Windows linkage requirement.
注意,WinMain
不是标准的。这只是 Windows 链接要求。
回答by GManNickG
回答by Ashish
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.
确保你至少有主力。我通过提供一个主要功能来修复我的。我编译的时候没有。我在 Windows 上 .. 似乎默认情况下它正在尝试寻找 winmain。
回答by Michael Yadidya
I have tried many solutions nothing worked for me.Then I re-created the project and moved the .cppfile to projectname/src/
.
我尝试了很多解决方案,但对我没有任何帮助。然后我重新创建了项目并将.cpp文件移动到projectname/src/
.
Tested in Eclipse.
在 Eclipse 中测试。