2

私は .c ファイルと main.c に分けられた 3 つの関数を持っています。

# Indicate that the compiler is the gcc compiler

CC=gc

# Indicate to the compiler to include header files in the local folder
CPPFLAGS = -I

main: method1.o
main: method2.o
main: method3.o
main: method4.o
main.o: main.h

メソッド 1,2,3,4 は main .c の関数であり、シェルで make と入力すると次の問題が発生します。

make
gcc  -I  -c -o method1.o method1.c
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [method1.o] Error 1
4

3 に答える 3

1

プロジェクトに次のファイルが含まれている場合:method1.c method2.c method3.c method4.cおよびmain.c

次のmakeファイルを使用できます

CPPFLAGS=-I/path/to/header/files
CC=gcc
all: main

%.o: %.c
    $(CC) $(CPPFLAGS)  -c -o $@ $^

main: method1.o method2.o method3.o method4.o main.o
    $(CC) -o $@ $^
于 2012-11-30T09:13:03.483 に答える
0
CC=gcc
CPPFLAGS=-I include
VPATH=src include
main: main.o method1.o method2.o method3.o method4.o -lm
    $(CC) $^ -o $@
main.o: main.c main.h
    $(CC) $(CPPFLAGS) -c $<
method1.o: method1.c
    $(CC) $(CPPFLAGS) -c $<
method2.o: method2.c
    $(CC) $(CPPFLAGS) -c $<
method3.o: method3.c
    $(CC) $(CPPFLAGS) -c $<
method4.o: method4.c
    $(CC) $(CPPFLAGS) -c $<

それはこのように働いた

于 2012-12-09T22:24:08.180 に答える
0

問題はあなたのCPPFLAGS定義にあります:

# Indicate to the compiler to include header files in the local folder
CPPFLAGS = -I

上記のコメントによると、.次のものがありません。

CPPFLAGS = -I.

それ以外の場合は、コマンド ラインの後に続く を、ヘッダーを検索できるディレクトリの名前としてgcc扱います。したがって、オプションに関する限り、完全なアプリケーションとしてリンクしようとするため、関数がないことを訴えるエラーメッセージが表示されます。-c-Igcc-c method1.cmain

于 2012-12-05T18:19:54.153 に答える