如何使用`python setup.py build`解决C ++ / C编译期间的“冲突类型”错误?
Posted
技术标签:
【中文标题】如何使用`python setup.py build`解决C ++ / C编译期间的“冲突类型”错误?【英文标题】:How to resolve a "conflicting types" error during C++/C compilation using `python setup.py build`? 【发布时间】:2013-12-26 02:55:54 【问题描述】:我正在尝试将 COLLADA DOM 库作为外部依赖项包含到我正在开发的程序 (PyMOL) 中,最终目标是能够以 COLLADA (.dae) 格式导出 3D 场景。我能够成功编译所有内容,直到将#include <Collada14Dom/dae.h>
添加到相关源文件中;即,如果我注释掉那一行,一切都很好。我正在使用 Xcode 5 运行 10.8.5 的 Mac。
到目前为止,我已经从 Sourceforge 安装了 COLLADA DOM v2.2,通过 make
(从“dom”子目录中)构建了 DOM,并通过 @987654328 将框架安装到 /Library/Frameworks/Collada14Dom.framework @。
我还下载了Boost v1.55.0 并通过./bootstrap
、./b2
、./b2 install
安装,如here 所示。
在我的COLLADA.cpp
文件中添加以下行后编译时出现问题。
#include <Collada14Dom/dae.h>
在编译时,我得到了一系列“冲突类型”的错误:
$ sudo /sw/bin/python setup.py build install --home=/opt/pymol --install-lib=/opt/pymol/modules --install-scripts=/opt/pymol
Password:
running install
running build
running build_py
running build_ext
building 'pymol._cmd' extension
gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -D_PYMOL_VMD_PLUGINS -D_PYMOL_LIBPNG -D_PYMOL_FREETYPE -D_PYMOL_INLINE -D_PYMOL_OPENGL_SHADERS -DNO_MMLIBS -D_PYMOL_CGO_DRAWARRAYS -D_PYMOL_CGO_DRAWBUFFERS -D_CGO_DRAWARRAYS -D_PYMOL_GL_CALLLISTS -DOPENGL_ES_2 -D_PYMOL_COLLADA -D_PYMOL_NUMPY -Iov/src -Ilayer0 -Ilayer1 -Ilayer2 -Ilayer3 -Ilayer4 -Ilayer5 -Imodules/cealign/src -Imodules/cealign/src/tnt -Ibuild/generated -Icontrib/uiuc/plugins/include -Icontrib/uiuc/plugins/molfile_plugin/src -I/sw/lib/python2.7/site-packages/numpy/core/include -I/usr/include -I/usr/X11/include -I/usr/X11/include/freetype2 -I/sw/include -I/sw/include/freetype2 -I/sw/include/python2.7 -c layer1/COLLADA.cpp -o build/temp.macosx-10.8-x86_64-2.7/layer1/COLLADA.o -ffast-math -funroll-loops -O3 -fcommon
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:67:
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:91:5: error: conflicting types for '__distance'
__distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
^
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:74:5: note: previous definition is here
__distance(_InputIterator __first, _InputIterator __last,
^
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:133:5: error: conflicting types for '__advance'
__advance(_BidirectionalIterator& __i, _Distance __n,
^
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:123:5: note: previous definition is here
__advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
^
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:149:5: error: conflicting types for '__advance'
__advance(_RandomAccessIterator& __i, _Distance __n,
^
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h:123:5: note: previous definition is here
__advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
In file included from /usr/include/c++/4.2.1/bits/stl_iterator.h:69:
/usr/include/c++/4.2.1/bits/cpp_type_traits.h:92:10: error: functions that differ only in their return type cannot be
overloaded
__two& __test_type(...);
^
/usr/include/c++/4.2.1/bits/cpp_type_traits.h:90:9: note: previous declaration is here
__one __test_type(int _Tp::*);
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:282:5: error: conflicting types for 'operator=='
operator==(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:96:5: note: previous definition is here
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:288:5: error: conflicting types for 'operator<'
operator<(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:102:5: note: previous definition is here
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:294:5: error: conflicting types for 'operator!='
operator!=(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:109:5: note: previous definition is here
operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:300:5: error: conflicting types for 'operator>'
operator>(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:115:5: note: previous definition is here
operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:306:5: error: conflicting types for 'operator<='
operator<=(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:121:5: note: previous definition is here
operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:312:5: error: conflicting types for 'operator>='
operator>=(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:127:5: note: previous definition is here
operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:332:5: error: conflicting types for 'operator=='
operator==(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:96:5: note: previous definition is here
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:338:5: error: conflicting types for 'operator<'
operator<(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:102:5: note: previous definition is here
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:344:5: error: conflicting types for 'operator!='
operator!=(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:109:5: note: previous definition is here
operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:350:5: error: conflicting types for 'operator>'
operator>(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:115:5: note: previous definition is here
operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:356:5: error: conflicting types for 'operator<='
operator<=(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:121:5: note: previous definition is here
operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:362:5: error: conflicting types for 'operator>='
operator>=(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_pair.h:127:5: note: previous definition is here
operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
In file included from layer1/COLLADA.cpp:35:
In file included from /Library/Frameworks/Collada14Dom.framework/Headers/dae.h:28:
In file included from /usr/local/include/boost/filesystem/convenience.hpp:22:
In file included from /usr/local/include/boost/filesystem/operations.hpp:25:
In file included from /usr/local/include/boost/filesystem/path.hpp:25:
In file included from /usr/local/include/boost/filesystem/path_traits.hpp:23:
In file included from /usr/local/include/boost/system/error_code.hpp:17:
In file included from /usr/local/include/boost/operators.hpp:86:
In file included from /usr/local/include/boost/iterator.hpp:17:
In file included from /usr/include/c++/4.2.1/iterator:68:
/usr/include/c++/4.2.1/bits/stl_iterator.h:368:5: error: conflicting types for 'operator-'
operator-(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.2.1/bits/stl_iterator.h:318:5: note: previous definition is here
operator-(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.2.1/bits/stl_iterator.h:738:5: error: conflicting types for 'operator=='
operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
^
/usr/include/c++/4.2.1/bits/stl_iterator.h:732:5: note: previous definition is here
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
^
/usr/include/c++/4.2.1/bits/stl_iterator.h:750:5: error: conflicting types for 'operator!='
operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
^
/usr/include/c++/4.2.1/bits/stl_iterator.h:744:5: note: previous definition is here
operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
error: command 'gcc' failed with exit status 1
显然 GCC 的 C++ 头文件存在问题,但我不确定如何解决。
一个重要的考虑因素是项目代码库中没有其他 C++ 代码。 (没有基于 C 的 COLLADA 库,我真的不想在这里重新发明***。)所以似乎需要进行一些配置——也许是 setup.py 中的一些设置。有没有办法告诉setup.py
使用GCC以外的东西来编译?
对于它的价值,我可以使用以下内容完全重现该问题(在安装 COLLADA DOM 和 Boost 之后):
sscce.cpp:
#ifdef __cplusplus
extern "C"
#endif
#include <Collada14Dom/dae.h>
int main()
return 0
#ifdef __cplusplus
// END extern "C"
#endif
如果我尝试使用gcc sscce.cpp
构建,则会产生与完整程序相同类型的“冲突类型”错误。奇怪的是(对我来说,无论如何),我使用g++ sscce.cpp
也遇到了同样的错误,所以我想这可能不是严格意义上的 GCC 问题。
我错过了什么?希望有人以前见过这种东西,并且您实际上不必安装 COLLADA DOM 和 Boost 即可提供建议,因为这两个库都需要一些时间来构建。一如既往,我们将不胜感激。
谢谢!
【问题讨论】:
为什么要在extern "C"
块中包含看似C++ 的标头?
从您的代码中删除 extern "C'
块。
删除这些块后,我现在遇到了与在 Collada DOM 框架内的子文件夹中查找包含相关的不同错误,但“冲突类型”错误消失了。这个 C++ 文件中的函数需要被项目中的其他 C 代码调用,所以我的印象是我需要将 C++ 代码包含在 extern "C"
块中以避免名称混淆。不是这样吗?
【参考方案1】:
此 C++ 文件中的函数需要可由其他 C 代码调用 项目,所以我的印象是我需要附上 C++ extern "C" 块中的代码以避免名称混淆。那不是 案例?
extern "C"
块允许将 C 声明嵌入到 C++ 代码中,而您希望相反;对此没有任何规定。
【讨论】:
以上是关于如何使用`python setup.py build`解决C ++ / C编译期间的“冲突类型”错误?的主要内容,如果未能解决你的问题,请参考以下文章
如何卸载使用“python setup.py develop”安装的 Python 站点包?