простая проблема с 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.

Спасибо.


person user237163    schedule 22.12.2009    source источник


Ответы (1)


Хорошо, проблема решена. мой вопрос был недостаточно описательным, чтобы решить проблему, я определял функции как встроенные в отдельном файле cpp, что заставляет компилятор жаловаться на неопределенные ссылки. Поэтому вместо этого я добавил реализации в заголовочный файл.

Спасибо.

person user237163    schedule 22.12.2009