UPDATEÇ未定義參照功能:發現這個問題。這是我的一個錯誤,與製作無關。我編輯了文件以刪除預處理器條件並對其進行了修改。GNU使庫包括
我試圖編譯使用一個makefile來處理包括由測試使用的功能文件庫的創建一個測試程序。當試圖做出最終的可執行文件時,我收到一個'未定義的引用'錯誤。以下是我的makefile和結果輸出。我試過在makefile中切換文件和操作的順序,但都導致失敗。這導致我相信我錯過了一些關鍵組件,而不需要重新排序我的操作。
我運行RHEL 4,如果該事項。執行後
CC=gcc
CFLAGS=-Wall
LDFLAGS=-lm
AR=ar
OBJ = \
test.o \
disk_alloc.o \
stringtools.o \
path.o \
xxmalloc.o
LIB = libtest.a
PROG = test
TAR = $(LIB) $(PROG)
all: $(TAR)
libtest.a: $(OBJ)
$(AR) -rv $(LIB) $(OBJ)
ranlib $(LIB)
$(PROG):
$(CC) $(CFLAGS) $(LIB) -o [email protected]
clean:
rm -f $(OBJ) $(TAR)
.PHONY: all clean
# vim: set noexpandtab tabstop=4:
輸出使:
gcc -Wall -c -o test.o test.c
gcc -Wall -c -o disk_alloc.o disk_alloc.c
gcc -Wall -c -o stringtools.o stringtools.c
gcc -Wall -c -o path.o path.c
gcc -Wall -c -o xxmalloc.o xxmalloc.c
ar -rv libtest.a test.o disk_alloc.o stringtools.o path.o xxmalloc.o
ar: creating libtest.a
a - test.o
a - disk_alloc.o
a - stringtools.o
a - path.o
a - xxmalloc.o
ranlib libtest.a
gcc -Wall libtest.a -o test
libtest.a(test.o): In function `disk_alloc_test_empty':
test.c:(.text+0x5f): undefined reference to `disk_alloc_create'
test.c:(.text+0x81): undefined reference to `disk_alloc_delete'
libtest.a(test.o): In function `disk_alloc_test_read_write':
test.c:(.text+0x17b): undefined reference to `disk_alloc_create'
test.c:(.text+0x1e0): undefined reference to `disk_alloc_delete'
libtest.a(test.o): In function `disk_alloc_test_nested':
test.c:(.text+0x30a): undefined reference to `disk_alloc_create'
test.c:(.text+0x372): undefined reference to `disk_alloc_create'
test.c:(.text+0x410): undefined reference to `disk_alloc_delete'
test.c:(.text+0x426): undefined reference to `disk_alloc_delete'
collect2: ld returned 1 exit status
make: *** [test] Error 1
disk_alloc.c'中的'disk_alloc_create'和'disk_alloc_delete'?你可以在'disk_alloc.o'文件和'libtest.a'庫中看到這些符號嗎?你也意識到RHEL 4是**非常**老,並且充滿** gaping **安全漏洞,對吧? (除了作爲在這一點完全沒有維護。) –
不考慮大洞的通話,是這兩個函數都在disk_alloc.c和存在於庫中。 – Duder
@伊坦 - 賴斯納望着disk_alloc.o文件,我竟然發現,disk_alloc_create和disk_alloc_delete符號都沒有找到,但他們是在圖書館。造成這種差異的原因是什麼?如何解決? – Duder