Fixed itk-3.20.1 on gcc-4.8, error: ‘memcpy’ was not declared in this scope

编译环境: Ubuntu 12.04, 本来自带4.6.3版本的gcc,但是之前为了编译某个程序,修改过gcc版本,现在系统默认gcc 4.8。编译安装官网下载来的InsightToolkit-3.20.1.tar.gz,出现如下奇怪错误:


[ 56%] Building CXX object Testing/Code/Common/CMakeFiles/itkCommonTests.dir/itkFloodFilledSpatialFunctionTest.o

In file included from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMath.h:28:0,

               from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkIndex.h:24,

               from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:30:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkConceptChecking.h: In member function ‘void itk::Concept::HasNumericTraits<T>::Constraints::constraints()’:

…...

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkConceptChecking.h: In member function ‘void itk::Concept::HasJoinTraits<T1, T2>::Constraints::constraints()’:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkConceptChecking.h:641:54: warning: typedef ‘ValueType’ locally defined but not used [-Wunused-local-typedefs]

     typedef typename JoinTraits<T1, T2>::ValueType ValueType;

                                                    ^

In file included from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:29:0:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkSize.h: In instantiation of ‘void itk::Size<VDimension>::SetSize(const SizeValueType*) [with unsigned int VDimension = 2u; itk::Size<VDimension>::SizeValueType = long unsigned int]’:

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:62:50:   required from here

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkSize.h:154:59: error: ‘memcpy’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

   { memcpy(m_Size, val, sizeof(SizeValueType)*VDimension); }

                                                         ^

In file included from /usr/include/features.h:357:0,

               from /usr/include/stdio.h:28,

               from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:27:

/usr/include/x86_64-linux-gnu/bits/string3.h:49:1: note: ‘void* memcpy(void*, const void*, size_t)’ declared here, later in the translation unit

__NTH (memcpy (void *__restrict __dest, __const void *__restrict __src,

^

In file included from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:30:0:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkIndex.h: In instantiation of ‘void itk::Index<VIndexDimension>::SetIndex(const IndexValueType*) [with unsigned int VIndexDimension = 2u; itk::Index<VIndexDimension>::IndexValueType = long int]’:

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:109:25:   required from here

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkIndex.h:227:66: error: ‘memcpy’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

   { memcpy(m_Index, val, sizeof(IndexValueType)*VIndexDimension); }

                                                                ^

In file included from /usr/include/features.h:357:0,

               from /usr/include/stdio.h:28,

               from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx:27:

/usr/include/x86_64-linux-gnu/bits/string3.h:49:1: note: ‘void* memcpy(void*, const void*, size_t)’ declared here, later in the translation unit

__NTH (memcpy (void *__restrict __dest, __const void *__restrict __src,

^

make[2]: *** [Testing/Code/Common/CMakeFiles/itkCommonTests.dir/itkFloodFilledSpatialFunctionTest.o] Error 1

make[1]: *** [Testing/Code/Common/CMakeFiles/itkCommonTests.dir/all] Error 2

make: *** [all] Error 2


怀疑是gcc版本问题,某些头文件编译顺序导致的一些库找不到。我打开/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkFloodFilledSpatialFunctionTest.cxx,试试添加头文件:

#include <string>

上面问题暂时没看到了,但是又出来下面问题:


[ 56%] Building CXX object Testing/Code/Common/CMakeFiles/itkCommonTests2.dir/itkMeshSourceGraftOutputTest.o

In file included from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMath.h:28:0,

               from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMatrixOffsetTransformBase.txx:23,

               from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMatrixOffsetTransformBase.h:457,

               from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkAffineTransform.h:24,

               from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:24:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkConceptChecking.h: In member function ‘void itk::Concept::HasNumericTraits<T>::Constraints::constraints()’:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkConceptChecking.h:558:59: warning: typedef ‘ValueType’ locally defined but not used [-Wunused-local-typedefs]

     typedef typename NumericTraits<T>::ValueType       ValueType;

                                                         ^

…...

In file included from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMatrixOffsetTransformBase.h:457:0,

               from /usr/local/src/InsightToolkit-3.20.1/Code/Common/itkAffineTransform.h:24,

               from /usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:24:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMatrixOffsetTransformBase.txx: In member function ‘virtual void itk::MatrixOffsetTransformBase<TScalarType, NInputDimensions, NOutputDimensions>::SetFixedParameters(const ParametersType&)’:

/usr/local/src/InsightToolkit-3.20.1/Code/Common/itkMatrixOffsetTransformBase.txx:317:46: warning: typedef ‘ParameterValueType’ locally defined but not used [-Wunused-local-typedefs]

  typedef typename ParametersType::ValueType ParameterValueType;

                                            ^

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx: In member function ‘virtual void itk::MeshSourceGraftOutputFilter<TInputMesh, TOutputMesh, TTransform>::GenerateData()’:

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:115:49: warning: typedef ‘InputPointsContainer’ locally defined but not used [-Wunused-local-typedefs]

  typedef typename TInputMesh::PointsContainer  InputPointsContainer;

                                               ^

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:116:49: warning: typedef ‘OutputPointsContainer’ locally defined but not used [-Wunused-local-typedefs]

  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;

                                               ^

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:118:56: warning: typedef ‘InputPointsContainerPointer’ locally defined but not used [-Wunused-local-typedefs]

  typedef typename TInputMesh::PointsContainerPointer  InputPointsContainerPointer;

                                                      ^

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:119:56: warning: typedef ‘OutputPointsContainerPointer’ locally defined but not used [-Wunused-local-typedefs]

  typedef typename TOutputMesh::PointsContainerPointer OutputPointsContainerPointer;

                                                      ^

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx: In instantiation of ‘void itk::MeshSourceGraftOutputFilter<TInputMesh, TOutputMesh, TTransform>::GenerateData() [with TInputMesh = itk::Mesh<int>; TOutputMesh = itk::Mesh<int>; TTransform = itk::AffineTransform<float, 3u>]’:

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:311:1:   required from here

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:153:36: error: ‘GraftOutput’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

  GraftOutput( filter->GetOutput() );

                                  ^

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:153:36: note: declarations in dependent base ‘itk::MeshSource<itk::Mesh<int> >’ are not found by unqualified lookup

/usr/local/src/InsightToolkit-3.20.1/Testing/Code/Common/itkMeshSourceGraftOutputTest.cxx:153:36: note: use ‘this->GraftOutput’ instead

make[2]: *** [Testing/Code/Common/CMakeFiles/itkCommonTests2.dir/itkMeshSourceGraftOutputTest.o] Error 1

make[1]: *** [Testing/Code/Common/CMakeFiles/itkCommonTests2.dir/all] Error 2

make: *** [all] Error 2


不知道什么情况!于是把gcc版本降到4.6.4,编译就一个问题都没报,能顺利安装成功!


Update

====================================

Jan 22, 2015. 今天重装ITK,同一个安装包,Ubuntu 12.04.5, gcc 4.8, g++ 4.8。仍然在56%,报同样错误:

error: ‘memcpy’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
     { memcpy(m_Size, val, sizeof(SizeValueType)*VDimension); }

这是编译器版本问题,将gcc降级为4.7.3还是报同样错误。解决方法:将gcc降级为4.6,错误消失

sudo apt-get install gcc-4.7 g++-4.7

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

gcc --version
bash: /usr/bin/gcc: No such file or directory

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20

gcc --version
gcc (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04) 4.7.3

<span style="color:#FF0000;">继续编译,仍然报同样错误。</span>

将gcc,g++降级为4.6

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

gcc --version
bash: /usr/bin/gcc: No such file or directory

sudo apt-get install gcc-4.6 g++-4.6

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20

g++ --version
g++ (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04) 4.6.4
错误消失。编译100%通过。


结论:实践证明InsightToolkit-3.20.1.tar.gz在Ubuntu 12.04,64bit,gcc 4.8/gcc 4.7版本上编译都会报同一个错误“‘memcpy’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]”。但在降级为gcc 4.6后,可100%完成通过。

你可能感兴趣的:(String,error,ubuntu,gcc,ITK)