何时退出(0)无法退出? [英] When will exit(0) fail to exit?

查看:72
本文介绍了何时退出(0)无法退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的节目大约有几千行。它需要来自

命令行的争论。

如果没有给出争论,它应该只是存在。以下是main()的
架构:


int main(int argc,char * argv [])

{

if(argc == 1)

{

cout<< NO ARGUEMENT<< endl;

退出(0);

}

//代码的其他部分


返回0; // LastLine


}

它还链接到其他库。

如果在命令行上没有给出争论,它只是输出NO

ARGUEMENT,然后挂起。

退出(0)无法退出。为什么exit(0)无法从main()退出?


如果我在命令行给出正确的争论,程序也会挂起。

返回0在LastLine也无法退出。


代码链接一些C ++库。它仅挂起在AIX系统上。但对于Linux来说,它是好的。为什么?


我发现可能是C ++库会导致问题。我该怎么办?

我必须链接该库。否则,链接器会抱怨

未定义的符号,尽管我的代码中不需要某些符号,

但是它们在其他库中使用。

谢谢。

My program is about several thousands lines. It takes arguements from
the command line.
If no arguement is given, it should simply exist. Below is the
architectureof main() :

int main(int argc, char *argv[])
{
if( argc == 1 )
{
cout << "NO ARGUEMENT"<<endl;
exit(0);
}
//Other parts of the code

return 0; //LastLine

}
It also links with other libraries.
If no arguement is given on command line, it only outputs "NO
ARGUEMENT", then hangs there.
The exit(0) can not exit. Why exit(0) fails to exit from main()?

If I give correct arguements at command line, the program also hangs.
The return 0 at the LastLine can not exit, either.

The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?

I find that maybe a C++ library causes the problem. What should I do?
I have to link that library. Otherwise, the linker complains
"Undefined symbols", although some symbols are not needed in my code,
but they are used in other libraries.
Thanks.

推荐答案

ju *** ***@gmail.com 写道:

我的程序大约有几千行。它需要来自

命令行的争论。

如果没有给出争论,它应该只是存在。以下是main()的
架构:
My program is about several thousands lines. It takes arguements from
the command line.
If no arguement is given, it should simply exist. Below is the
architectureof main() :



#include< cstdlib>

#include <cstdlib>


int main(int argc,char * argv [])

{
int main(int argc, char *argv[])
{



using namespace std;

using namespace std;


>

if(argc == 1)

{

cout<< NO ARGUEMENT<< endl;

退出(0);

}


//其他部分代码


返回0; // LastLine


}


它还链接到其他图书馆。

如果没有给出命令的争论它只输出NO

ARGUEMENT,然后挂起。

退出(0)无法退出。为什么exit(0)无法从main()退出?


如果我在命令行给出正确的争论,程序也会挂起。

返回0在LastLine也无法退出。


代码链接一些C ++库。它仅挂起在AIX系统上。但对于Linux来说,它是好的。为什么?


我发现可能是C ++库会导致问题。我该怎么办?

我必须链接该库。否则,链接器会抱怨

未定义的符号,尽管我的代码中不需要某些符号,

但是它们在其他库中使用。
>
if( argc == 1 )
{
cout << "NO ARGUEMENT"<<endl;
exit(0);
}
//Other parts of the code

return 0; //LastLine

}
It also links with other libraries.
If no arguement is given on command line, it only outputs "NO
ARGUEMENT", then hangs there.
The exit(0) can not exit. Why exit(0) fails to exit from main()?

If I give correct arguements at command line, the program also hangs.
The return 0 at the LastLine can not exit, either.

The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?

I find that maybe a C++ library causes the problem. What should I do?
I have to link that library. Otherwise, the linker complains
"Undefined symbols", although some symbols are not needed in my code,
but they are used in other libraries.



假设你包含< cstdlibas我在上面做了,这听起来像是你的编译器的一个错误。但是,您不需要调用exit()。一个简单的返回

0;声明就足够了。


Supposing you included <cstdlibas I did above, it sounds like a bug of
your compiler. However you do not need to call exit(). A simple "return
0;" statement would suffice.


ju******@gmail.com 写道:

>

代码链接一些C ++库。它仅挂起在AIX系统上。但对于Linux来说,它是好的。为什么?
>
The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?



您是否按照clc上的要求给出了任何建议?


-

Ian Collins。

Did you follow any of the advice given when you asked this on c.l.c?

--
Ian Collins.


1月20日,7:23 * pm,Ian Collins< ian-n ... @ hotmail.comwrote:
On Jan 20, 7:23*pm, Ian Collins <ian-n...@hotmail.comwrote:

junw2 ... @ gmail.com写道:
junw2...@gmail.com wrote:

代码链接一些C ++库。它仅挂起在AIX系统上。但对于Linux来说,它是好的。为什么?
The code links some C++ libraries. It only hangs on AIX systems. But
for Linux, it works fine. Why?



当你在clc上询问时,你是否遵循了给出的任何建议?


-

伊恩柯林斯。


Did you follow any of the advice given when you asked this on c.l.c?

--
Ian Collins.



我发现我链接的一个库会导致问题。它

定义了一个静态对象。我的代码不使用该静态对象。当

退出main()时,析构函数被调用并挂起。

但为什么它在某些系统上有效?


谢谢。

I find that one of the library that I link causes the problem. It
defines a static object. My code does not use that static object. When
exit the main(), the destructor is called and hangs.
But why it works on some systems?

Thanks.


这篇关于何时退出(0)无法退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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