我正在尝试使用NetBeans cygwin g ++编译器构建项目(rar file)。
我可以通过在ubuntu下的 src / 目录中运行make
来构建它。然而,在cygwin下,它一直给我undefined reference to...
。
(在编译之前,我已在 src / Makefile 中将CC = g++
更改为CC = g++-3
。)
错误表示undefined reference to BufMgr::pinPage(int, Page*&, int, char const*)
,其中pinPage()
位于 include / 。
这是项目的结构。
project/
include/
buf.h (where pinPage() was defined)
other header files
src/
Makefile
other source files
以下是原始Makefile和错误。
生成文件:
#
# Makefile for CS564 Minibase project. Needs GNU make.
#
# Define DEBUGREL for some kind of debugging output (not from us, from
# the original Minibase implementors.)
#
# Warning: make depend overwrites this file.
.PHONY: depend clean backup setup
MAIN = btree
MINIBASE = ..
CC = g++
#CFLAGS = -DUNIX -Wall -g
CFLAGS = -g
INCLUDES = -I${MINIBASE}/include -I.
LFLAGS = -L. -lbtree -lm
SRCS = main.C btree_driver.C btfile.C btindex_page.C btleaf_page.C btree_file_scan.C key.C db.C new_error.C sorted_page.C system_defs.C
OBJS = $(SRCS:.C=.o)
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) $(OBJS) -o $(MAIN) $(LFLAGS)
.C.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
depend: $(SRCS)
makedepend $(INCLUDES) $^
clean:
rm -f *.o *~ $(MAIN)
rm -f my_output
backup:
-mkdir bak
cp Makefile *.[Ch] bak
run:
rm -rf my_output
./btree > my_output
# Grab the sources for a user who has only the makefile
setup:
/bin/cp -i $(MINIBASE)/src/*.[Ch] .
/bin/cp -i $(MINIBASE)/src/*.sample .
# DO NOT DELETE THIS LINE -- make depend needs it
Erorr:
$ make
g++-3 -g -I../include -I. -c main.C
g++-3 -g -I../include -I. -c btree_driver.C
g++-3 -g -I../include -I. -c btfile.C
g++-3 -g -I../include -I. -c btindex_page.C
g++-3 -g -I../include -I. -c btleaf_page.C
g++-3 -g -I../include -I. -c btree_file_scan.C
g++-3 -g -I../include -I. -c key.C
g++-3 -g -I../include -I. -c db.C
g++-3 -g -I../include -I. -c new_error.C
g++-3 -g -I../include -I. -c sorted_page.C
g++-3 -g -I../include -I. -c system_defs.C
g++-3 -g -I../include -I. main.o btree_driver.o btfile.o btindex_page.o btleaf_page.o btree_file_scan.o key.o db.o new_error.o sorted_page.o system_defs.o -o btree -L. -lbtree -lm
btfile.o: In function `_ZN9BTreeFileC2ER6StatusPKc':
/cygdrive/c/Users/Trantor/Documents/NetBeansProjects/DB-HW6/src/btfile.C:78: undefined reference to `BufMgr::pinPage(int, Page*&, int, char const*)'
btfile.o: In function `_ZN9BTreeFileC1ER6StatusPKc':
/cygdrive/c/Users/Trantor/Documents/NetBeansProjects/DB-HW6/src/btfile.C:78: undefined reference to `BufMgr::pinPage(int, Page*&, int, char const*)'
btfile.o: In function `_ZN9BTreeFileC2ER6StatusPKc8AttrTypeii':
.....
答案 0 :(得分:0)
这可能是,因为文件扩展名似乎是.C
。区分大小写的文件系统(Unix),大写.C
扩展意味着C ++代码,而小写.c
意味着普通的旧C代码。因此编译器可能会尝试将其编译为C代码,这将生成不同的函数名称。
如果这是原因,那么可能的修复:
-x c++
,快速谷歌搜索).cpp
,并修复Makefile中的扩展程序