• 12884阅读
  • 5回复

[已找到原因]template with C linkage错误 [复制链接]

上一主题 下一主题
离线米尔利安
 

只看楼主 倒序阅读 楼主  发表于: 2011-11-22
环境:Ubuntu 8.04 + Qt4.7.3静态编译
(这个环境曾经成功编译过其他的QT程序,所以不应该有问题哇)
qmake -o Makefile生成Makefile。
make的时候报类似如下的错误

In file included from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qwidget.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QWidget:1,
                 from ./time.h:4,
                 from /usr/include/sys/types.h:133,
                 from /usr/include/stdlib.h:320,
                 from /usr/include/c++/4.2/cstdlib:72,
                 from /usr/include/c++/4.2/bits/stl_algobase.h:68,
                 from /usr/include/c++/4.2/bits/char_traits.h:46,
                 from /usr/include/c++/4.2/string:47,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qstring.h:60,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qobject.h:48,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qcoreapplication.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qapplication.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QApplication:1,
                 from main.cpp:1:
/usr/local/Trolltech/Qt-4.7.3/include/QtGui/qwindowdefs.h:89: error: template with C linkage
/usr/local/Trolltech/Qt-4.7.3/include/QtGui/qwindowdefs.h:142: error: template with C linkage
/usr/local/Trolltech/Qt-4.7.3/include/QtGui/qwindowdefs.h:145: error: template with C linkage
In file included from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qwidget.h:47,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QWidget:1,
                 from ./time.h:4,
                 from /usr/include/sys/types.h:133,
                 from /usr/include/stdlib.h:320,
                 from /usr/include/c++/4.2/cstdlib:72,
                 from /usr/include/c++/4.2/bits/stl_algobase.h:68,
                 from /usr/include/c++/4.2/bits/char_traits.h:46,
                 from /usr/include/c++/4.2/string:47,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qstring.h:60,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qobject.h:48,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qcoreapplication.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qapplication.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QApplication:1,
                 from main.cpp:1:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qmargins.h:81: error: template specialization with C linkage
In file included from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qrect.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qpaintdevice.h:46,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qwidget.h:48,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QWidget:1,
                 from ./time.h:4,
                 from /usr/include/sys/types.h:133,
                 from /usr/include/stdlib.h:320,
                 from /usr/include/c++/4.2/cstdlib:72,
                 from /usr/include/c++/4.2/bits/stl_algobase.h:68,
                 from /usr/include/c++/4.2/bits/char_traits.h:46,
                 from /usr/include/c++/4.2/string:47,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qstring.h:60,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qobject.h:48,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qcoreapplication.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qapplication.h:45,
                 from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QApplication:1,
                 from main.cpp:1:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:83: error: declaration of C function ‘bool operator==(const QSize&, const QSize&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qmargins.h:121: error: previous declaration ‘bool operator==(const QMargins&, const QMargins&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:84: error: declaration of C function ‘bool operator!=(const QSize&, const QSize&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qmargins.h:130: error: previous declaration ‘bool operator!=(const QMargins&, const QMargins&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:88: error: declaration of C function ‘const QSize operator*(qreal, const QSize&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:87: error: previous declaration ‘const QSize operator*(const QSize&, qreal)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:95: error: template specialization with C linkage
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:102: error: declaration of C function ‘QDataStream& operator<<(QDataStream&, const QSize&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qmargins.h:140: error: previous declaration ‘QDebug operator<<(QDebug, const QMargins&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h: In function ‘const QSize operator*(const QSize&, qreal)’:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:168: error: declaration of C function ‘const QSize operator*(const QSize&, qreal)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:88: error: previous declaration ‘const QSize operator*(qreal, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h: In function ‘const QSize operator*(qreal, const QSize&)’:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:171: error: declaration of C function ‘const QSize operator*(qreal, const QSize&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:168: error: previous declaration ‘const QSize operator*(const QSize&, qreal)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h: At global scope:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:198: error: declaration of C function ‘QDebug operator<<(QDebug, const QSize&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:102: error: previous declaration ‘QDataStream& operator<<(QDataStream&, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:233: error: declaration of C function ‘bool operator==(const QSizeF&, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:156: error: previous declaration ‘bool operator==(const QSize&, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:234: error: declaration of C function ‘bool operator!=(const QSizeF&, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:159: error: previous declaration ‘bool operator!=(const QSize&, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:235: error: declaration of C function ‘const QSizeF operator+(const QSizeF&, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:162: error: previous declaration ‘const QSize operator+(const QSize&, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:236: error: declaration of C function ‘const QSizeF operator-(const QSizeF&, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:165: error: previous declaration ‘const QSize operator-(const QSize&, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:237: error: declaration of C function ‘const QSizeF operator*(const QSizeF&, qreal)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:171: error: previous declaration ‘const QSize operator*(qreal, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:238: error: declaration of C function ‘const QSizeF operator*(qreal, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:237: error: previous declaration ‘const QSizeF operator*(const QSizeF&, qreal)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:239: error: declaration of C function ‘const QSizeF operator/(const QSizeF&, qreal)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:181: error: previous declaration ‘const QSize operator/(const QSize&, qreal)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:247: error: template specialization with C linkage
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:255: error: declaration of C function ‘QDataStream& operator<<(QDataStream&, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:198: error: previous declaration ‘QDebug operator<<(QDebug, const QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:256: error: declaration of C function ‘QDataStream& operator>>(QDataStream&, QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:103: error: previous declaration ‘QDataStream& operator>>(QDataStream&, QSize&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h: In function ‘const QSizeF operator*(const QSizeF&, qreal)’:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:326: error: declaration of C function ‘const QSizeF operator*(const QSizeF&, qreal)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:238: error: previous declaration ‘const QSizeF operator*(qreal, const QSizeF&)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h: In function ‘const QSizeF operator*(qreal, const QSizeF&)’:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:329: error: declaration of C function ‘const QSizeF operator*(qreal, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:326: error: previous declaration ‘const QSizeF operator*(const QSizeF&, qreal)’ here
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h: At global scope:
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:361: error: declaration of C function ‘QDebug operator<<(QDebug, const QSizeF&)’ conflicts with
/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qsize.h:255: error: previous declaration ‘QDataStream& operator<<(QDataStream&, const QSizeF&)’ here
(后面还有许多)

非常迷惑,搜了很多也没有答案,求助ing。


我们在天上的父,愿人都尊你的名为圣。
愿你的国降临。
愿你的旨意行在地上,如同行在天上。
离线dbzhang800

只看该作者 1楼 发表于: 2011-11-22
猜一下,你不是在告诉编译器你的是一个C程序了吧?比如后缀 .c
离线米尔利安

只看该作者 2楼 发表于: 2011-11-22
后缀都是.cpp啊。。。
我们在天上的父,愿人都尊你的名为圣。
愿你的国降临。
愿你的旨意行在地上,如同行在天上。
离线dbzhang800

只看该作者 3楼 发表于: 2011-11-22
引用第2楼米尔利安于2011-11-22 15:14发表的  :
后缀都是.cpp啊。。。

你没提供其他信息,还是只能让别人乱猜,比如:你使用 extern "C"  这些东西了?
离线米尔利安

只看该作者 4楼 发表于: 2011-11-22
搞定了………………完全低级错误原因………………

有一个类的头文件写成time.h 导致了这个错误……………………
我们在天上的父,愿人都尊你的名为圣。
愿你的国降临。
愿你的旨意行在地上,如同行在天上。
离线latecomer22
只看该作者 5楼 发表于: 2012-05-23
  我今天也碰到类似的问题了,我忘记用extern C了
快速回复
限100 字节
 
上一个 下一个