2009-12-22 5 views
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, который включает в себя как заголовки атрибута, так и объекты.

проблема в том, что я продолжаю получать неопределенные ссылки на функции, используемые в 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

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

Спасибо.

Смежные вопросы