我在编译项目时遇到问题我正在为我给出的主文件编码文件wordbench2.h,wordbench2.cpp,makefile.wb2,oaa_bst.h(main_wb2.cpp)我想知道是否有人看错了在我的makefile中
LIB = /home/courses/cop4530p/LIB
CPP = $(LIB)/cpp
TCPP = $(LIB)/tcpp
PROJ = .
INCPATH = -I$(PROJ)-I$(CPP)-I$(TCPP)
CC = g++ -std=c++11 -Wall -Wextra -I. -I$(CPP)
#target:
all: wb2.x foaa.x moaa.x
#foaa+.x
main_wb2.o: wordbench2.h main_wb2.cpp
$(CC) -c main_wb2.cpp
foaa.o: wordbench2.h foaa.cpp
$(CC) -c foaa.cpp
moaa.o: wordbench2.h moaa.cpp
$(CC) -c moaa.cpp
wordbench2.o: wordbench2.h wordbench2.cpp wordify.cpp
$(CC) -c wordbench2.cpp
xstring.o: $(CPP)/xstring.h $(CPP)/xstring.cpp
$(CC) $(INCPATH) -c $(CPP)/xstring.cpp
wb2.x: main_wb2.o wordbench2.o xstring.o
$(CC) -o wb2.x main_wb2.o
foaa.x: foaa.o wordbench2.o xstring.o
$(CC) -o foaa.x foaa.o
moaa.x: moaa.o wordbench2.o xstring.o
$(CC) -o moaa.x moaa.o
错误
g++ -std=c++11 -Wall -Wextra -I. -I/home/courses/cop4530p/LIB/cpp -o wb2.x main_wb2.o
main_wb2.o: In function `main':
main_wb2.cpp:(.text+0xfd): undefined reference to `WordBench::WordBench()'
main_wb2.cpp:(.text+0x109): undefined reference to `fsu::String::String()'
main_wb2.cpp:(.text+0x115): undefined reference to `fsu::String::String()'
main_wb2.cpp:(.text+0x1ad): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)'
main_wb2.cpp:(.text+0x1c4): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x1f1): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x21e): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)'
main_wb2.cpp:(.text+0x235): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x25d): undefined reference to `WordBench::ReadText(fsu::String const&, bool)'
main_wb2.cpp:(.text+0x28f): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)'
main_wb2.cpp:(.text+0x2a6): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x2d3): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x300): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)'
main_wb2.cpp:(.text+0x317): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x33f): undefined reference to `WordBench::ReadText(fsu::String const&, bool)'
main_wb2.cpp:(.text+0x371): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)'
main_wb2.cpp:(.text+0x388): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x3b5): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x3e2): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)'
main_wb2.cpp:(.text+0x3f9): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x42f): undefined reference to `WordBench::WriteReport(fsu::String const&, unsigned short, unsigned short, std::_Ios_Fmtflags, std::_Ios_Fmtflags) const'
main_wb2.cpp:(.text+0x44d): undefined reference to `fsu::String::operator=(fsu::String const&)'
main_wb2.cpp:(.text+0x45e): undefined reference to `fsu::String::Size() const'
main_wb2.cpp:(.text+0x488): undefined reference to `fsu::String::Cstr() const'
main_wb2.cpp:(.text+0x4d9): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)'
main_wb2.cpp:(.text+0x572): undefined reference to `WordBench::ClearData()'
main_wb2.cpp:(.text+0x595): undefined reference to `WordBench::ShowSummary() const'
main_wb2.cpp:(.text+0x67a): undefined reference to `fsu::String::~String()'
main_wb2.cpp:(.text+0x686): undefined reference to `fsu::String::~String()'
main_wb2.cpp:(.text+0x695): undefined reference to `WordBench::~WordBench()'
main_wb2.cpp:(.text+0x6cb): undefined reference to `fsu::String::~String()'
main_wb2.cpp:(.text+0x6dc): undefined reference to `fsu::String::~String()'
main_wb2.cpp:(.text+0x6f0): undefined reference to `WordBench::~WordBench()'
collect2: error: ld returned 1 exit status
make: *** [wb2.x] Error 1
答案 0 :(得分:0)
在这条规则中:
wb2.x: main_wb2.o wordbench2.o xstring.o
$(CC) -o wb2.x main_wb2.o
您在先决条件列表中列出了wordbench2.o
和xstring.o
,但您没有将它们放入编译行。
你为什么一遍又一遍地改写同样的东西?这只会导致像这样的愚蠢错误。使用automatic variables可以避免重新输入错误并将其弄错:
wb2.x: main_wb2.o wordbench2.o xstring.o
$(CC) -o $@ $^
同样适用于其他链接器规则。