0
我有一个程序,编译使用以下:makefile或头文件的简单问题?
g++ -I ../../include -I . -I ../ -I ../../ -I ../ Entity.cpp Attribute.cpp main.cpp -o main.o
的Attribute.cpp包括它的头文件,Attribute.h和Attribute.cpp包含Attribute.h的所有实施方式。
Entity.cpp包含头文件Entity.h和Attribute.h,因为Entity.cpp使用了Attribute类。
main.cpp文件包含一个名为XML.h的头文件,它只包含Attribute和Entity头文件。
问题是我不断收到对main.cpp和Entity.cpp中使用函数的未定义引用。
/tmp/ccxKUUNI.o: In function `Entity::entityString() const': Entity.cpp:(.text+0x3b0): undefined reference to `Attribute::getValueString() const' Entity.cpp:(.text+0x3c0): undefined reference to `Attribute::getName() const' /tmp/ccxKUUNI.o: In function `Entity::findAttributePosition(std::basic_string, std::allocator > const&)': Entity.cpp:(.text+0xb4e): undefined reference to `Attribute::equals(std::basic_string, std::allocator > const&) const' /tmp/ccxKUUNI.o: In function `Entity::findAttributePositionConst(std::basic_string, std::allocator > const&) const': Entity.cpp:(.text+0xc24): undefined reference to `Attribute::equals(std::basic_string, std::allocator > const&) const' /tmp/ccxKUUNI.o: In function `Entity::getAttributeValueString(std::basic_string, std::allocator > const&) const': Entity.cpp:(.text+0xe0a): undefined reference to `Attribute::getValueString() const' /tmp/ccvaLwbi.o: In function `main': main.cpp:(.text+0x2bc): undefined reference to `Entity::addAttribute(Attribute const&)' main.cpp:(.text+0x359): undefined reference to `Entity::addAttribute(Attribute const&)' main.cpp:(.text+0x4bb): undefined reference to `Entity::addAttribute(Attribute const&)' main.cpp:(.text+0x61d): undefined reference to `Entity::addAttribute(Attribute const&)' main.cpp:(.text+0x77f): undefined reference to `Entity::addAttribute(Attribute const&)' /tmp/ccvaLwbi.o:main.cpp:(.text+0x8e1): more undefined references to `Entity::addAttribute(Attribute const&)' follow /tmp/ccvaLwbi.o: In function `main': main.cpp:(.text+0xc65): undefined reference to `Entity::addEntity(Entity const&)' main.cpp:(.text+0xd68): undefined reference to `Entity::addAttribute(Attribute const&)' main.cpp:(.text+0xea9): undefined reference to `Entity::addEntity(Entity const&)' main.cpp:(.text+0xee1): undefined reference to `Entity::addEntity(Entity const&)' main.cpp:(.text+0xf53): undefined reference to `Entity::addEntity(Entity const&)'
我知道这些函数的定义,因为它们的实现都写在相应的cpp文件,即。 Entity.cpp和Attribute.cpp。
谢谢。