0

我试图用 NetBeans cygwin g++ 编译器构建一个项目( rar 文件)。我可以通过在 ubuntu 下makesrc/目录中运行来构建它。但是,在cygwin下,它一直给我undefined reference to...

(在编译之前,我已经更改CC = g++CC = g++-3in src/Makefile。)

错误说undefined reference to BufMgr::pinPage(int, Page*&, int, char const*), wherepinPage()位于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 

错误:

$ 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':

.....
4

1 回答 1

0

这可能是因为文件扩展名似乎是.C. 在区分大小写的文件系统 (Unix) 上,大写.C扩展表示 C++ 代码,而小写.c表示普通的旧 C 代码。因此编译器可能会尝试将其编译为 C 代码,这将产生不同的函数名称。

如果这是原因,那么可能的修复:

  • 通过向 CFLAGS 添加正确的编译开关来强制 gcc 编译 C++(-x c++快速谷歌搜索)
  • 将文件重命名为.cpp, 并修复 Makefile 中的扩展名
于 2012-12-18T08:10:02.620 回答