-1

Ubuntu 64 ビットがインストールされており、フラグを使用して C ファイルをコンパイルすると、次のようになります。

gcc -g -m32 -ansi -Wall -c -o *.o *.c

ファイルをコンパイルしますが、ターミナルで実行しようとしても何も起こりません。

そこで、次のコードを使用して、makefile を使用せずに単純なファイルを 1 つだけコンパイルして実行することにしました。

#include <stdio.h>
int main()
{
    printf("Hello World");
    return 0;
}

コンパイルは成功しますが、ファイルを実行しようとすると何も得られません...

注: lib32gcc1、libc6-i386、および g++-multilib のインストールは既に試みました。

この問題を解決するにはどうすればよいですか?

4

3 に答える 3

2

-o *.o を -o programname に置き換えます。-o パラメーターは、生成するプログラムの実行可能ファイル名を受け取ります。そして、ここにgccマニュアルがあります:

http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Overall-Options.html#Overall-Options

于 2013-03-16T14:13:11.510 に答える
1

簡単なテストのために、すべてのオプションを除外します。

> cat test.c
#include <stdio.h>
int main()
{
  printf("Hello World\n");
  return 0;
}

> gcc test.c

> ./a.out
Hello World

それが機能するかどうかを確認します。

于 2013-03-16T12:56:52.163 に答える
0

Let us assume you (already) have two object files a.o and b.o, their corresponding source file a.c and b.c and some common header ch.h; then your (incorrect) command line

 gcc -g -m32 -ansi -Wall -c -o *.o *

might be expanded as:

 gcc -g -m32 -ansi -Wall -c -o a.o b.o a.c b.c ch.h a.o b.o

(actually, that would be even worse, e.g. if you have some Makefile or some backup files from your editors like a.c~, as remarked by William Pursell)

which would compile but not link, the files b.o a.c b.c ch.h a.o b.o which does not means much.

You should understand that the shell is expanding first the arguments before executing any gcc program (in a new process). To understand what is expanded, consider replacing gcc by echo (or by gcc -v which would show what is really happening)

次に、GCC の呼び出しに関する GCC のドキュメントを読む必要があります。

実際には、 Advanced Bash Scripting Guide (おそらく間違いがあるかもしれません) やAdvanced Linux Programmingなどを読むのに数時間を費やす必要があります。いくつかのウィキペディアのページも読むのに役立ちます。

于 2013-03-16T13:02:04.000 に答える