• 4520阅读
  • 1回复

TI Davinci xdc 环境编译 examples/hello 出错,提示:vtable for Hello [复制链接]

上一主题 下一主题
离线love_mcu
 

只看楼主 倒序阅读 楼主  发表于: 2009-03-11
编译 examples 下的 hello,总是在构造,和解析function 出错误,提示`vtable for Hello‘ 是什么意思?

package/cfg/app_debug/main.o470MV(.text+0x3e8): In function `main':
/usr/local
3-arm/include/qstring.h:851: undefined reference to `vtable for Hello'
离线love_mcu

只看该作者 1楼 发表于: 2009-03-13
这个问题已解决,原因如下:


在使用qt的时候,常常为了实现的需求将一些类隐藏在cpp中文件实现,而这些类又需要一些qt自己的机制支持如Q_OBJECT宏。于是在编译的时候,很可能出现像undefined reference to vtable for "xxx::xxx"的问题,这其实是由于qt不会自动moc cpp文件。参考qt的文档,发现最简单的方法就是用qmake重新生成makefile文件就可以了。另外就是直接把该类写在.h文件里面在编译。

如果需要自己重新写makefile,qt文档给出了以下的方法

For Q_OBJECT class declarations in header files, here is a useful makefile rule if you only use GNU make:

moc_%.cpp: %.h
         moc $(DEFINES) $(INCPATH) $< -o $@

If you want to write portably, you can use individual rules of the following form:

moc_foo.cpp: foo.h
         moc $(DEFINES) $(INCPATH) $< -o $@

You must also remember to add moc_foo.cpp to your SOURCES (substitute your favorite name) variable and moc_foo.o or moc_foo.obj to your OBJECTS variable.

Both examples assume that $(DEFINES) and $(INCPATH) expand to the define and include path options that are passed to the C++ compiler. These are required by moc to preprocess the source files.

While we prefer to name our C++ source files .cpp, you can use any other extension, such as .C, .cc, .CC, .cxx, and .c++, if you prefer.

For Q_OBJECT class declarations in implementation (.cpp) files, we suggest a makefile rule like this:

foo.o: foo.moc
foo.moc: foo.cpp

         moc $(DEFINES) $(INCPATH) -i $< -o $@

This guarantees that make will run the moc before it compiles foo.cpp. You can then put


#include "foo.moc"



对于.cpp文件里面的Q_OBJECT,我们只需在makefile文件里面添加


foo.o: foo.moc
foo.moc: foo.cpp

         moc $(DEFINES) $(INCPATH) -i $< -o $@

这样的规则就可以了,然后在.cpp文件的末尾写上

#include "foo.moc"

这样就能够正确的编译,不过我最推荐的还是用qmake重新生成makefile。
快速回复
限100 字节
 
上一个 下一个