繁体   English   中英

如何使用“ python setup.py build”解决C ++ / C编译期间的“冲突类型”错误?

[英]How to resolve a “conflicting types” error during C++/C compilation using `python setup.py build`?

我试图将COLLADA DOM库作为外部依赖项包含在我正在研究的程序( PyMOL )中,其最终目标是能够以COLLADA(.dae)格式导出3D场景。 我可以成功编译所有内容,直到将#include <Collada14Dom/dae.h>到相关源文件中#include <Collada14Dom/dae.h> 即,如果我注释掉那一行,一切都会很好。 我正在使用Xcode 5运行10.8.5的Mac。

到目前为止,我已经从Sourceforge安装了COLLADA DOM v2.2 ,通过make (从“ dom”子目录中)构建了DOM,并通过make install将框架安装到了/Library/Frameworks/Collada14Dom.framework。

我也下载了升压v1.55.0 ,并通过安装./bootstrap./b2./b2 install指示在这里

COLLADA.cpp添加到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进行构建, gcc sscce.cpp产生与整个程序相同类型的“冲突类型”错误。 奇怪的是(无论如何对我而言),使用g++ sscce.cpp也会出现相同的错误,因此我想这可能并不是严格意义上的GCC问题。

我想念什么? 希望有人以前见过这种情况,并且您实际上不必安装COLLADA DOM和Boost就能提供建议,因为这两个库都需要一些时间来构建。 一如既往,任何帮助将不胜感激。

谢谢!

这个C ++文件中的函数必须可由项目中的其他C代码调用,因此给我的印象是,我需要将C ++代码放在外部的“ C”块中,以避免名称修饰。 不是吗?

extern "C"块允许将C声明嵌入C ++代码中,而您想要相反的话; 没有为此准备。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM