链接器错误 [英] linker error

查看:63
本文介绍了链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我刚刚开始掌握C ++并完成了教程。

然而,甚至连标准你好世界"运动锻炼:(我

确实得到链接器错误[链接器错误]未解析的外部''WinMain''

引自C:\ PATROGRAM FILES \ BORLAND \CBUILDER5 \LIB\C0W32.OBJ"


我的代码(Borland C ++ builder 5)如下:

#include< condefs .h>

#include< iostream.h>

#include< conio.h>

#pragma hdrstop


// ---------------------------------------- -----------------------------------

int main(int argc,char ** argv)

{

cout<<<"Hello World!"<< endl;

cout< < endl<<"按任意键继续..." ;;

getch();

返回0;

}

有什么想法吗?


感谢!


kath

解决方案

ka ********** @ web.de 写道:

我刚刚开始掌握C ++,并完成了教程。

但是,甚至连标准的hello world都没有。运动锻炼:(我

确实得到链接器错误[链接器错误]未解析的外部''WinMain''

引自C:\ PATROGRAM FILES \ BORLAND \CBUILDER5 \LIB\C0W32.OBJ"


我的代码(Borland C ++ builder 5)如下:


# include< condefs.h>

#include< iostream.h>

#include< conio.h>

#pragma hdrstop


// ------------------------------------ ---------------------------------------

int main( int argc,char ** argv)

{

cout<<"" Hello World!"<< endl;

cout<< endl<<"按任意键继续..." ;;

getch();

返回0;

}


任何想法?



不幸的是,是的。你正在构建这个作为Windows应用程序。

如果是这样,那么你的应用程序并不是以主要开头的必须在''WinMain''开始

,你没有,这就是链接器是什么,b $ b抱怨。 MS Windows编程不仅仅是

普通编程。这就是为什么你可能想要搁置

" Windows"现在的事情的一面,并切换到创建已知的

作为控制台应用程序。请参阅

帮助系统中为编译器描述的适当设置。或者在新闻组中询问您的编译器(参见''borland.public。*''层次结构)




V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要''请问


2007-07-23 17:40, ka ********** @ web.de 写道:





我刚刚开始掌握C ++,并完成了教程。

然而,甚至连标准的hello world都没有。运动锻炼:(我

确实得到链接器错误[链接器错误]未解析的外部''WinMain''

引自C:\ PATROGRAM FILES \ BORLAND \CBUILDER5 \LIB\C0W32.OBJ"


我的代码(Borland C ++ builder 5)如下:


# include< condefs.h>



非标准标题,未使用,跳过它。


#include< iostream.h>



旧标题,现在包含所有标准标题而没有.h

后缀,所以它应该只是#include< iostream>


#include< conio.h>



非 - 标准,在学习C ++时远离这些标题通常是个好主意,因为它减少了学习任何坏习惯的变化。


#pragma hdrstop


非标准,我不知道它的作用。保留它,如果你认为它是有用的,但考虑到pragma的名称,它可能是应该在头文件中使用的



// --------------------------------- ------------------------------------------

int main(int argc,char ** argv)



除非你实际解析命令行参数,否则我建议使用更简单的
form:int main()。


{

cout<< Hello World! << ENDL;



这应该给你一个编译错误,cout没有定义。

包括命名空间(std :: cout<< ...)或put''使用命名空间std;''

在主函数之上。我更喜欢第一个,但那只是我。


cout<< endl<< 按任意键继续......;



同上。


getch();



如果仅用于防止控制台在程序完成后立即关闭,我认为最好使用std :: cin.get()需要

你按Enter键。如果你使用这个你可以摆脱

conio.h的包含。


返回0;

}


有什么想法吗?



当你在项目中创建

时(或者Borland称之为),你可能已经将它指定为windows GUI程序,你需要将它指定为

本机win32项目。


顺便说一句,在我看来,Borland C ++ Builder 5已经很老了

现在,至少有一个较新的版本出来了,你可能想要考虑升级你的b $ b。如果成本是一个问题,那么有免费的替代品,包括MS和DevC ++(随gcc一起提供)的C ++ 2005.


-

Erik Wikstr?m


7月23日17:55,Victor Bazarov < v.Abaza ... @ comAcast.netwrote:


kath.neum ... @ web.de写道:


我刚刚开始掌握C ++并完成了教程。

然而,甚至连标准的hello world都没有。运动锻炼:(我

确实得到链接器错误[链接器错误]未解析的外部''WinMain''

引自C:\ PATROGRAM FILES \ BORLAND \CBUILDER5 \LIB \C0W32.OBJ"


我的代码(Borland C ++ builder 5)如下:


#include< condefs.h>

#include< iostream.h>

#include< ; conio.h>

#pragma hdrstop


// ------------ -------------------------------------------------- -------------

int main(int argc,char ** argv)

{

cout <<"< endl;

cout<< endl<<"按任意键继续..." ;;

getch();

返回0;

}


有什么想法?



不幸的是,是的。你正在构建一个Windows应用程序。

如果是这样,那么你的应用程序不会以''main''开头,它必须启动

in ''WinMain'',你没有,那就是链接器是什么,b $ b抱怨。 MS Windows编程不仅仅是

普通编程。这就是为什么你可能想要搁置

" Windows"现在的事情的一面,并切换到创建已知的

作为控制台应用程序。请参阅

帮助系统中为编译器描述的适当设置。或者在新闻组中询问您的编译器(参见''borland.public。*''层次结构)




V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要''请问



你好Victor,

现在正在运行,谢谢你的帮助!我创建它作为控制台

应用程序,这确实是原因。感谢这个提示:-)

干杯,

凯瑟琳


Hi,

I just started to get a grip on C++ and and went through the tutorial.
However, not even the standard "hello world" exercise works out :( I
do get a linker error "[Linker Error] Unresolved external ''WinMain''
referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\C0W32.OBJ"

my code (Borland C++ builder 5) is as follows:
#include <condefs.h>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------
int main (int argc, char **argv)
{
cout << "Hello World!" << endl;
cout << endl << "press any key to continue...";
getch();
return 0;
}
Any idea?

THANKS!

kath

解决方案

ka**********@web.de wrote:

I just started to get a grip on C++ and and went through the tutorial.
However, not even the standard "hello world" exercise works out :( I
do get a linker error "[Linker Error] Unresolved external ''WinMain''
referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\C0W32.OBJ"

my code (Borland C++ builder 5) is as follows:
#include <condefs.h>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------
int main (int argc, char **argv)
{
cout << "Hello World!" << endl;
cout << endl << "press any key to continue...";
getch();
return 0;
}
Any idea?

Unfortunately, yes. You''re building this as a Windows application.
If so, then your application doesn''t start in ''main'', it has to start
in ''WinMain'', which you don''t have and that''s what the linker is
complaining about. MS Windows programming is not the same as just
plain programming. That''s why you probably want to set aside the
"Windows" side of things for now and switch to creating what is known
as "Console Applications". See appropriate settings described in the
help system for your compiler. Or ask in the newsgroup dedicated to
your compiler (see the ''borland.public.*'' hierarchy).

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


On 2007-07-23 17:40, ka**********@web.de wrote:

Hi,

I just started to get a grip on C++ and and went through the tutorial.
However, not even the standard "hello world" exercise works out :( I
do get a linker error "[Linker Error] Unresolved external ''WinMain''
referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\C0W32.OBJ"

my code (Borland C++ builder 5) is as follows:
#include <condefs.h>

Non-standard header, and not used, skip it.

#include <iostream.h>

Old header, nowadays all standard headers are included without the .h
suffix, so it should be just #include <iostream>

#include <conio.h>

Non-standard, it''s generally a good idea to stay away from such headers
while learning C++, since it reduces the changes of learning any bad habits.

#pragma hdrstop

Non-standard and I don''t know what it does. Keep it if you think it''s
useful, but considering the name of the pragma it''s probably something
that should be used in header-files.

//---------------------------------------------------------------------------
int main (int argc, char **argv)

Unless you actually parse the command line arguments I would recommend
to use the simpler form: int main().

{
cout << "Hello World!" << endl;

This should give you a compiler error, cout is not defined. Either
include the namespace (std::cout << ...) or put ''using namespace std;''
above the main-function. I prefer the first but that''s just me.

cout << endl << "press any key to continue...";

Ditto.

getch();

If used just to prevent the console from closing as soon as the program
is done, I think it''s better to use std::cin.get() which will require
you to press enter. If you use this you can get rid of the include for
conio.h also.

return 0;
}
Any idea?

You have probably specified it as a windows GUI program when you created
the project (or whatever Borland calls it), you need to specify it as a
native win32 project.

By the way, it seems to me that Borland C++ Builder 5 is quite old by
now, at least one newer version is out and you might want to consider
upgrading. If cost is an issue there are free alternatives, both Visual
C++ 2005 from MS and DevC++ (which comes with gcc).

--
Erik Wikstr?m


On 23 Jul., 17:55, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:

kath.neum...@web.de wrote:

I just started to get a grip on C++ and and went through the tutorial.
However, not even the standard "hello world" exercise works out :( I
do get a linker error "[Linker Error] Unresolved external ''WinMain''
referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\C0W32.OBJ"

my code (Borland C++ builder 5) is as follows:

#include <condefs.h>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop

//---------------------------------------------------------------------------
int main (int argc, char **argv)
{
cout << "Hello World!" << endl;
cout << endl << "press any key to continue...";
getch();
return 0;
}

Any idea?


Unfortunately, yes. You''re building this as a Windows application.
If so, then your application doesn''t start in ''main'', it has to start
in ''WinMain'', which you don''t have and that''s what the linker is
complaining about. MS Windows programming is not the same as just
plain programming. That''s why you probably want to set aside the
"Windows" side of things for now and switch to creating what is known
as "Console Applications". See appropriate settings described in the
help system for your compiler. Or ask in the newsgroup dedicated to
your compiler (see the ''borland.public.*'' hierarchy).

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask

Hi Victor,
it is running now, thanks for your help!!! I created it as console
application, that was indeed the reason. thanks for this tip :-)
Cheers,
Kathleen


这篇关于链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆