0

我有一个使用以下内容编译的程序:

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:在函数“Entity::entityString() const”中:
Entity.cpp:(.text+0x3b0): 未定义的对 `Attribute::getValueString() const' 的引用
Entity.cpp:(.text+0x3c0): undefined reference to `Attribute::getName() const'
/tmp/ccxKUUNI.o:在函数“Entity::findAttributePosition(std::basic_string, std::allocator > const&)”中:
Entity.cpp:(.text+0xb4e): 未定义引用 `Attribute::equals(std::basic_string, std::allocator > const&) const'
/tmp/ccxKUUNI.o:在函数 `Entity::findAttributePositionConst(std::basic_string, std::allocator > const&) const'中:
Entity.cpp:(.text+0xc24): 未定义引用 `Attribute::equals(std::basic_string, std::allocator > const&) const'
/tmp/ccxKUUNI.o:在函数 `Entity::getAttributeValueString(std::basic_string, std::allocator > const&) const'中:
Entity.cpp:(.text+0xe0a): 未定义的对 `Attribute::getValueString() const' 的引用
/tmp/ccvaLwbi.o:在函数“主”中:
main.cpp:(.text+0x2bc): 对 `Entity::addAttribute(Attribute const&)' 的未定义引用
main.cpp:(.text+0x359): 对 `Entity::addAttribute(Attribute const&)' 的未定义引用
main.cpp:(.text+0x4bb): 对 `Entity::addAttribute(Attribute const&)' 的未定义引用
main.cpp:(.text+0x61d): 对 `Entity::addAttribute(Attribute const&)' 的未定义引用
main.cpp:(.text+0x77f): 对 `Entity::addAttribute(Attribute const&)' 的未定义引用
/tmp/ccvaLwbi.o:main.cpp:(.text+0x8e1): 更多未定义的对 `Entity::addAttribute(Attribute const&)' 的引用如下
/tmp/ccvaLwbi.o:在函数“主”中:
main.cpp:(.text+0xc65): undefined reference to `Entity::addEntity(Entity const&)'
main.cpp:(.text+0xd68): 对 `Entity::addAttribute(Attribute const&)' 的未定义引用
main.cpp:(.text+0xea9): 对 `Entity::addEntity(Entity const&)' 的未定义引用
main.cpp:(.text+0xee1): 对 `Entity::addEntity(Entity const&)' 的未定义引用
main.cpp:(.text+0xf53): undefined reference to `Entity::addEntity(Entity const&)'

我知道这些函数是定义的,因为它们的实现写在相应的 cpp 文件中,即。Entity.cpp 和 Attribute.cpp。

谢谢。

4

1 回答 1

0

好的,问题解决了。我的问题描述性不够,无法回答问题,我在单独的 cpp 文件中将函数定义为内联函数,这导致编译器抱怨未定义的引用。因此,我将实现添加到头文件中。

谢谢。

于 2009-12-22T22:33:55.290 回答