Netbeans cygwing++;生成错误:未定义对的引用

Netbeans cygwing++;生成错误:未定义对的引用,netbeans,g++,cygwin,undefined-reference,Netbeans,G++,Cygwin,Undefined Reference,我试图用NetBeans cygwin g++编译器构建一个项目()。 我可以通过在ubuntu下的src/目录中运行make来构建它。然而,在cygwin下,它不断地给我未定义的引用… (在编译之前,我在src/Makefile中将CC=g++更改为CC=g++-3) 该错误表示,对BufMgr::pinPage(int,Page*&,int,char const*)的未定义引用,其中pinPage()位于include/位置 这是项目的结构 project/ include/

我试图用NetBeans cygwin g++编译器构建一个项目()。 我可以通过在ubuntu下的src/目录中运行
make
来构建它。然而,在cygwin下,它不断地给我
未定义的引用…

(在编译之前,我在src/Makefile中将
CC=g++
更改为
CC=g++-3

该错误表示,
对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 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 

这可能是因为文件扩展名似乎是
.C
。在区分大小写文件系统(UNIX)、Capital <代码> .c>代码>扩展意味着C++代码,而小写<代码> .c>代码意味着普通的旧C代码。所以编译器可能会尝试将其编译为C代码,这将产生不同的函数名

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

    <> LI>强制GCC编译C++,通过将右编译开关添加到cFLAGS(<代码> -x C++ +代码>,快速Google)< <
  • 将文件重命名为
    .cpp
    ,并修复Makefile中的扩展名

无法说出问题所在,因为您没有显示完整的错误。但是,可以推断这是一个链接器错误,这意味着有一个对象文件或库需要链接,但没有链接。我已将错误和project dir结构附加到问题。缺少的函数是否在头文件中完全定义,或者头文件中是否有源文件?否。include/buf.h将BufMgr::pinPage()定义为
状态pinPage(int PageId_in_a_DB,Page*&Page,int emptyPage=0,const char*filename=NULL)。在src/或include/中都没有完全定义该函数。因此实际上没有实现该函数?我尝试了
-xc++
。但是它给了我
main.o:1:1:error:trassed'\1'在程序main.o:1:1:error:trassed'\20'在程序main.o:1:4:warning:null字符忽略main.o:1:1:error:trassed'\210'在程序main.o:1:11:warning:null字符忽略main.o:1:14:warning:null字符忽略…
@transtor不向link命令提供CFLAGS。或者,将
-x
直接添加到compile命令行。谢谢。但事实证明这是源错误(它已经将它们视为.cpp)。
$ 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':

.....