我有一个使用以下内容编译的程序:
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。
感谢。
答案 0 :(得分:0)
好的,问题解决了。我的问题没有足够的描述性来解决问题, 我在单独的cpp文件中将函数定义为内联,这会导致编译器抱怨未定义的引用。因此我将实现添加到头文件中。
感谢。