新人求助, 请问如果在ubuntu下跑一个"hello world"
本人初次使用ubuntu, 想在上面跑一个hello world, 请问应该如何操作?我知道, 这种问题实在过于笼统, 令高手不懈, 令前辈不齿, 令大侠汗颜, 令.....
我只想知道, 在什么地方可以找到学习如何 makefile?
在什么地方可以找到学习如何使用 gcc?
完全没明白你要干嘛。。。
我问的很'复杂'么?我的意思是, 在VC下, 新建一个win32 console application, 写好程序, 编译通过, 就可以运行.
如果是ubuntu, 同样想写一个程序, 应该怎样完成? [quote]原帖由 [i]btbtbtbtbt[/i] 于 2008-3-18 14:41 发表 [url=http://bbs.linuxpk.com/redirect.php?goto=findpost&pid=44278&ptid=13308][img]http://bbs.linuxpk.com/images/common/back.gif[/img][/url]
我问的很'复杂'么?
我的意思是, 在VC下, 新建一个win32 console application, 写好程序, 编译通过, 就可以运行.
如果是ubuntu, 同样想写一个程序, 应该怎样完成? [/quote]
首先,打开终端(终端的位置在应用程序-->附件-->终端),然后在命令行敲入vim hello.c,然后,按i键,然后输入helloworld程序,然后按esc,然后连续快速的按大写的Z两次,然后,在命令行输入gcc hello.c -Wall,然后在命令行输入./a.out,然后你就看到了你想要的结果。
向cugbcat 学习啊!
向cugbcat 学习啊!:L hello,world程序[code]#include <stdio>
int main(int argc, char *argv[])
{
printf("hello,world\n");
return 0;
}[/code] [quote]原帖由 [i]cnangel[/i] 于 2008-3-20 08:53 发表 [url=http://bbs.linuxpk.com/redirect.php?goto=findpost&pid=44358&ptid=13308][img]http://bbs.linuxpk.com/images/common/back.gif[/img][/url]
hello,world程序#include
int main(int argc, char *argv[])
{
printf("hello,world\n");
return 0;
} [/quote]
看看这个helloworld程序:lol[code]/* hello.c -- print a greeting message and exit.
Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2005, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include "system.h"
/* String containing name the program is called with. */
const char *program_name;
static const struct option longopts[] =
{
{ "greeting", required_argument, NULL, 'g' },
{ "help", no_argument, NULL, 'h' },
{ "next-generation", no_argument, NULL, 'n' },
{ "traditional", no_argument, NULL, 't' },
{ "version", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
static void print_help (void);
static void print_version (void);
int
main (int argc, char *argv[])
{
int optc;
int t = 0, n = 0, lose = 0;
const char *greeting = NULL;
program_name = argv[0];
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
#if ENABLE_NLS
/* Set the text message domain. */
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
/* Even exiting has subtleties. The /dev/full device on GNU/Linux
can be used for testing whether writes are checked properly. For
instance, hello >/dev/null should exit unsuccessfully. On exit,
if any writes failed, change the exit status. This is
implemented in the Gnulib module "closeout". */
atexit (close_stdout);
while ((optc = getopt_long (argc, argv, "g:hntv", longopts, NULL)) != -1)
switch (optc)
{
/* One goal here is having --help and --version exit immediately,
per GNU coding standards. */
case 'v':
print_version ();
exit (EXIT_SUCCESS);
break;
case 'g':
greeting = optarg;
break;
case 'h':
print_help ();
exit (EXIT_SUCCESS);
break;
case 'n':
n = 1;
break;
case 't':
t = 1;
break;
default:
lose = 1;
break;
}
if (lose || optind < argc)
{
/* Print error message and exit. */
if (optind < argc)
fprintf (stderr, _("%s: extra operand: %s\n"),
program_name, argv[optind]);
fprintf (stderr, _("Try `%s --help' for more information.\n"),
program_name);
exit (EXIT_FAILURE);
}
/* Print greeting message and exit. */
if (t)
printf (_("hello, world\n"));
else if (n)
/* TRANSLATORS: Use box drawing characters or other fancy stuff
if your encoding (e.g., UTF-8) allows it. If done so add the
following note, please:
[Note: For best viewing results use a UTF-8 locale, please.]
*/
printf (_("\
+---------------+\n\
| Hello, world! |\n\
+---------------+\n\
"));
else
{
if (!greeting)
greeting = _("Hello, world!");
puts (greeting);
}
exit (EXIT_SUCCESS);
}
/* Print help info. This long message is split into
several pieces to help translators be able to align different
blocks and identify the various pieces. */
static void
print_help (void)
{
/* TRANSLATORS: --help output 1 (synopsis)
no-wrap */
printf (_("\
Usage: %s [OPTION]...\n"), program_name);
/* TRANSLATORS: --help output 2 (brief description)
no-wrap */
fputs (_("\
Print a friendly, customizable greeting.\n"), stdout);
puts ("");
/* TRANSLATORS: --help output 3: options 1/2
no-wrap */
fputs (_("\
-h, --help display this help and exit\n\
-v, --version display version information and exit\n"), stdout);
puts ("");
/* TRANSLATORS: --help output 4: options 2/2
no-wrap */
fputs (_("\
-t, --traditional use traditional greeting format\n\
-n, --next-generation use next-generation greeting format\n\
-g, --greeting=TEXT use TEXT as the greeting message\n"), stdout);
printf ("\n");
/* TRANSLATORS: --help output 5 (end)
TRANSLATORS: the placeholder indicates the bug-reporting address
for this application. Please add _another line_ with the
address for translation bugs.
no-wrap */
printf (_("\
Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
}
/* Print version and copyright information. */
static void
print_version (void)
{
printf ("hello (GNU %s) %s\n", PACKAGE, VERSION);
/* xgettext: no-wrap */
puts ("");
/* It is important to separate the year from the rest of the message,
as done here, to avoid having to retranslate the message when a new
year comes around. */
printf (_("\
Copyright (C) %s Free Software Foundation, Inc.\n\
License: GNU GPL v2+ <http://www.gnu.org/licenses/gpl.html>\n\
This is free software. There is NO WARRANTY, to the extent permitted by law.\n"),
"2006");
}[/code] 一个HELLOWORLD能写出如楼上大大这么夸张的,在下真是佩服的五体投地。 [quote]原帖由 [i]choatrue[/i] 于 2008-3-20 10:31 发表 [url=http://bbs.linuxpk.com/redirect.php?goto=findpost&pid=44362&ptid=13308][img]http://bbs.linuxpk.com/images/common/back.gif[/img][/url]
一个HELLOWORLD能写出如楼上大大这么夸张的,在下真是佩服的五体投地。 [/quote]
这个是GNU开发的,专门有人维护,难道你不能从中学到很多东西吗? 1.
fprintf (stderr, _("%s: extra operand: %s\n"),
program_name, argv[optind]);
================================================================
2.
printf (_("\
+---------------+\n\
| Hello, world! |\n\
+---------------+\n\
"));
==================================================================
3.
printf (_("\
Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
==================================================================
一直没弄清, 这些输出格式都是printf(_("..."),... )
fprintf (..., _("..."),...);
中 _() 的作用, 为何这么写, 这个是一个宏定义吗?
这样写是为了美观吗? 还是为了别的。 写个.c文件,编译一下,在shell里执行下,这是我想到的,简单了点 用bash shell也可以啊。建一个文本,内容为:
#! /bin/bash
clear
echo "Hello World!"
echo ""
保存后在shell下用“chmod 711 文件名”命令,文件名按实际填写。
然后用“./文件名”就行了。
页:
[1]