[Insight-users] Help with "Undefined references during linking"

Luis Ibanez luis.ibanez at kitware.com
Tue Apr 4 10:32:28 EDT 2006


Hi Martin,

Thanks for posting the exact error messages that you are getting.

The problem seems to be that in your CMakeLists.txt file you
forgot to add the itkFSLAffineTransformFileReader.cxx file
to the list of object files to be compiled in order to form the
executable itkFSLAffineTransformFileReaderTest.

You only put the Test for it:  itkFSLAffineTransformFileReaderTest.cxx


so, The line that currently has:



    ADD_EXECUTABLE(
          itkFSLAffineTransformFileReaderTest
          itkFSLAffineTransformFileReaderTest.cxx
          )



shold be modified to have:



    ADD_EXECUTABLE(
          itkFSLAffineTransformFileReaderTest
          itkFSLAffineTransformFileReader.cxx
          itkFSLAffineTransformFileReaderTest.cxx
          )



    Regards,



        Luis


---------------------
Martin Kavec wrote:
> Luis,
> 
> I am on Linux, gcc (GCC) 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9), 
> ITK-2.6.0.
> 
> kavec at signal08 $ make
> /usr/bin/cmake -H/home/kavec/Projects/itkFSLAffineTransformFileReader 
> -B/home/kavec/Projects/itkFSLAffineTransformFileReader --check-build-system 
> CMakeFiles/Makefile.cmake 0
> make -f CMakeFiles/Makefile2 all
> make[1]: Entering directory 
> `/home/kavec/Projects/itkFSLAffineTransformFileReader'
> make -f CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/build.make 
> CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/depend
> make[2]: Entering directory 
> `/home/kavec/Projects/itkFSLAffineTransformFileReader'
> make[2]: Nothing to be done for 
> `CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/depend'.
> make[2]: Leaving directory 
> `/home/kavec/Projects/itkFSLAffineTransformFileReader'
> make -f CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/build.make 
> CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/build
> make[2]: Entering directory 
> `/home/kavec/Projects/itkFSLAffineTransformFileReader'
> Linking CXX executable itkFSLAffineTransformFileReaderTest
> /usr/bin/cmake -E remove -f itkFSLAffineTransformFileReaderTest
> c++     -ftemplate-depth-50  -fPIC   
> "CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/itkFSLAffineTransformFileReaderTest.o"   
> -o itkFSLAffineTransformFileReaderTest -rdynamic -L/opt/ITK_debug/bin 
> -lITKStatistics -lITKCommon -lITKNumerics -lITKMetaIO -lITKIO -lITKNrrdIO 
> -litkgdcm -litkjpeg12 -litkjpeg16 -litkopenjpeg -litkpng -litktiff -litkjpeg8 
> -lITKSpatialObject -lITKNumerics -lITKCommon -litkvnl_inst -litkvnl_algo 
> -litkvnl -litkvcl -litknetlib -lm -litksys -lpthread -ldl -lITKMetaIO 
> -lITKDICOMParser -lITKEXPAT -lITKniftiio -lITKznz -litkzlib -lm
> CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/itkFSLAffineTransformFileReaderTest.o: 
> In function `main':
> itkFSLAffineTransformFileReaderTest.cxx:(.text+0x1c8): undefined reference to 
> `itk::FSLAffineTransformFileReader::Update()'
> CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/itkFSLAffineTransformFileReaderTest.o: 
> In function `itk::FSLAffineTransformFileReader::New()':
> itkFSLAffineTransformFileReaderTest.cxx:
> (.gnu.linkonce.t._ZN3itk28FSLAffineTransformFileReader3NewEv+0x6d): undefined 
> reference to 
> `itk::FSLAffineTransformFileReader::FSLAffineTransformFileReader()'
> CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/itkFSLAffineTransformFileReaderTest.o: 
> In function 
> `itk::ObjectFactory<itk::FSLAffineTransformFileReader>::Create()':
> itkFSLAffineTransformFileReaderTest.cxx:
> (.gnu.linkonce.t._ZN3itk13ObjectFactoryINS_28FSLAffineTransformFileReaderEE6CreateEv+0xd): 
> undefined reference to `typeinfo for itk::FSLAffineTransformFileReader'
> itkFSLAffineTransformFileReaderTest.cxx:
> (.gnu.linkonce.t._ZN3itk13ObjectFactoryINS_28FSLAffineTransformFileReaderEE6CreateEv+0x4e): 
> undefined reference to `typeinfo for itk::FSLAffineTransformFileReader'
> collect2: ld returned 1 exit status
> make[2]: *** [itkFSLAffineTransformFileReaderTest] Error 1
> make[2]: Leaving directory 
> `/home/kavec/Projects/itkFSLAffineTransformFileReader'
> make[1]: *** [CMakeFiles/itkFSLAffineTransformFileReaderTest.dir/all] Error 2
> make[1]: Leaving directory 
> `/home/kavec/Projects/itkFSLAffineTransformFileReader'
> make: *** [all] Error 2
> kavec at signal08 $
> 
> Thanks.
> 
> Martin
> 
> On Tuesday 04 April 2006 13:14, Luis Ibanez wrote:
> 
>>Hi Martin,
>>
>>Please post the *exact* error messages that you get.
>>
>>Are you compiling this on Linux ? or Windows ?
>>
>>
>>   Please let us know,
>>
>>
>>      Thanks
>>
>>
>>         Luis
>>
>>
>>
>>---------------------
>>
>>Martin Kavec wrote:
>>
>>>Hi,
>>>
>>>I am writing a piece of IO code to read a FSL affine transform file. The
>>>transform is (always) stored in an ASCII file as a 4x4 matrix, so it is
>>>should not be a "rocket science" to read it.
>>>
>>>My code is based on Code/IO/itkTransformFileREader.cxx, except that
>>>the ::Update() method will be different. I attached the header,
>>>implementation, CMakeList.txt and small test code to make it easier to
>>>compile.
>>>
>>>The code compiles fine, but the linker complains about missing references
>>>to ::Update(), ::New() and ::Create() methods.
>>>
>>>I tried to figure out what's wrong, but no luck, so I would appreciate a
>>>help. Thanks.
>>>
>>>Martin
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>PROJECT( itkFSLAffineTransformFileReader )
>>>
>>>FIND_PACKAGE(ITK)
>>>IF(ITK_FOUND)
>>>  INCLUDE(${ITK_USE_FILE})
>>>ELSE(ITK_FOUND)
>>>  MESSAGE(FATAL_ERROR
>>>            "Cannot build InsightApplications without ITK.  Please set
>>>ITK_DIR.") ENDIF(ITK_FOUND)
>>>
>>>SET(CMAKE_VERBOSE_MAKEFILE ON)
>>>ADD_DEFINITIONS(-Wall)
>>>
>>>INCLUDE_REGULAR_EXPRESSION(".*")
>>>
>>>ADD_EXECUTABLE(itkFSLAffineTransformFileReaderTest
>>>itkFSLAffineTransformFileReaderTest.cxx )
>>>TARGET_LINK_LIBRARIES(itkFSLAffineTransformFileReaderTest ITKStatistics
>>>ITKCommon ITKNumerics ITKMetaIO ITKIO)
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>/*=======================================================================
>>>==
>>>
>>>  Program:   Insight Segmentation & Registration Toolkit
>>>  Module:    $RCSfile: itkFSLAffineTransformFileReader.cxx,v $
>>>  Language:  C++
>>>  Date:      $Date: 2006/04/02 12:00:00 $
>>>  Version:   $Revision: 1.0 $
>>>
>>>     This software is distributed WITHOUT ANY WARRANTY; without even
>>>     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
>>>     PURPOSE.  See the above copyright notices for more information.
>>>
>>>=========================================================================
>>>*/ #ifndef __itkFSLAffineTransformFileReader_cxx
>>>#define __itkFSLAffineTransformFileReader_cxx
>>>
>>>#include "itkFSLAffineTransformFileReader.h"
>>>
>>>#include <itksys/ios/sstream>
>>>
>>>namespace itk
>>>{
>>>
>>>/** Constructor */
>>>FSLAffineTransformFileReader::FSLAffineTransformFileReader()
>>>{
>>>  m_FileName = "";
>>>
>>>  TransformPointer m_Transform = TransformType::New();
>>>  m_Transform->SetIdentity();
>>>}
>>>
>>>/** Destructor */
>>>FSLAffineTransformFileReader::~FSLAffineTransformFileReader()
>>>{
>>>}
>>>
>>>/** Update the Reader */
>>>void FSLAffineTransformFileReader::Update()
>>>{
>>>}
>>>
>>>
>>>} // namespace itk
>>>
>>>#endif
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>#if defined(_MSC_VER)
>>>#pragma warning ( disable : 4786 )
>>>#endif
>>>
>>>#ifdef __BORLANDC__
>>>#define ITK_LEAN_AND_MEAN
>>>#endif
>>>
>>>#include "itkFSLAffineTransformFileReader.h"
>>>
>>>#include "itkAffineTransform.h"
>>>
>>>int main(int argc, char* argv[])
>>>{
>>>
>>>  if( argc < 1 )
>>>  {
>>>     std::cerr << "Usage: " << std::endl;
>>>     std::cerr << argv[0] << " fsl.mat"
>>>               << std::endl;
>>>    return EXIT_FAILURE;
>>>
>>>  }
>>>
>>>  typedef itk::FSLAffineTransformFileReader TransformReaderType;
>>>  TransformReaderType::Pointer transformReader =
>>>TransformReaderType::New();
>>>
>>>  transformReader->SetFileName( argv[1] );
>>>
>>>  try{
>>>     transformReader->Update();
>>>  }
>>>  catch(itk::ExceptionObject & excp ) {
>>>     std::cerr << "Error while reading the transform from file: " <<
>>>argv[1] << std::endl; std::cerr << excp << std::endl;
>>>     return EXIT_FAILURE;
>>>  }
>>>
>>>  typedef itk::AffineTransform< double, 3 > AffineTransformType;
>>>  AffineTransformType::Pointer fslTransform =
>>>transformReader->GetTransform();
>>>
>>>  fslTransform->Print( std::cout );
>>>
>>>  return EXIT_SUCCESS;
>>>}
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>/*=======================================================================
>>>==
>>>
>>>  Program:   Insight Segmentation & Registration Toolkit
>>>  Module:    $RCSfile: itkFSLAffineTransformFileReader.h,v $
>>>  Language:  C++
>>>  Date:      $Date: 2006/04/02 12:00:00 $
>>>  Version:   $Revision: 1.0 $
>>>
>>>     This software is distributed WITHOUT ANY WARRANTY; without even
>>>     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
>>>     PURPOSE.  See the above copyright notices for more information.
>>>
>>>=========================================================================
>>>*/ #ifndef __itkFSLAffineTransformFileReader_h
>>>#define __itkFSLAffineTransformFileReader_h
>>>
>>>#include "itkLightProcessObject.h"
>>>#include "metaTransform.h"
>>>#include "itkAffineTransform.h"
>>>
>>>namespace itk
>>>{
>>>
>>>class FSLAffineTransformFileReader : public LightProcessObject
>>>{
>>>public:
>>>
>>>  /** SmartPointer typedef support */
>>>  typedef FSLAffineTransformFileReader Self;
>>>  typedef SmartPointer< Self > Pointer;
>>>  typedef AffineTransform< double, 3u > TransformType;
>>>  typedef TransformType::ParametersType ParametersType;
>>>  typedef TransformType::Pointer TransformPointer;
>>>
>>>  /** Method for creation through the object factory */
>>>  itkNewMacro( Self );
>>>
>>>  /** Run-time type information (and related methods). */
>>>  typedef Object Superclass;
>>>  itkTypeMacro( FSLAffineTransformFileReader, LightProcessObject );
>>>
>>>  /** Set the filename  */
>>>  itkSetStringMacro( FileName );
>>>
>>>  /** Get the filename */
>>>  itkGetStringMacro( FileName );
>>>
>>>  /** Get transform macro */
>>>  TransformPointer GetTransform( ) const {
>>>     return m_Transform;
>>>  }
>>>
>>>  /** Write out the transform */
>>>  void Update();
>>>
>>>protected:
>>>
>>>  std::string m_FileName;
>>>
>>>  FSLAffineTransformFileReader();
>>>  virtual ~FSLAffineTransformFileReader();
>>>
>>>private:
>>>
>>>  TransformPointer m_Transform;
>>>
>>>};
>>>
>>>} // namespace itk
>>>
>>>
>>>#endif // __itkFSLAffineTransformFileReader_h
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
> 
> 



More information about the Insight-users mailing list