LNK 2019 LNK1120 error

I'm using Microsoft visual studios and cmake wrapper to write a script with the insight toolkit package... just beginning and having some I/O errors. I'm very new to using object oriented programming, so don't feel you'll insult me if you answer as you would to a 2 year old.

Reg_script.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// sjk Project begun 130524
// 1st order of business, create ITK functions to read in png files and convert them to mha files

#include "IO.h"
#include "itkImage.h"
#include <iostream>
#include <string>


int main(int argc, char *argv[])
{
	typedef itk::Image<double,2> ImageType;
	typedef itk::ImageFileReader<ImageType> ReaderType;
	
	ReaderType::Pointer in_read = ReaderType::New();
        Read_Raw_Data(in_read, argv[1]); //call function to read data
	ImageType::Pointer in_image = in_read->GetOutput();
	
	std::cerr << "image start: " << std::endl;
	std::cerr << in_image->GetRequestedRegion().GetSize() << std::endl;

  return EXIT_SUCCESS;
}


IO.h
1
2
3
4
5
6
7
8
#include <iostream>
#include <string>
#include "itkImageFileReader.h"

typedef itk::Image<double,2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;

void Read_Raw_Data(ReaderType::Pointer, char *);


IO.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// sjk 130524 this source file should contain all of the input/output operations on this data

#include <iostream>
#include <string>
#include "itkImageFileReader.h"
#include "IO.h"


void Read_Raw_Data(ReaderType::Pointer reader, char *filename) { //input raw data
		
  typedef itk::ImageFileReader<ImageType> ReaderType; 
  ReaderType::Pointer reader = ReaderType::New(); 
  reader->SetFileName(argv[1]); 

} //Read_Raw_Data 


Cmakelists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

cmake_minimum_required(VERSION 2.8)
 
project(Reg_script)
 
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
else()
  find_package(ItkVtkGlue REQUIRED)
  include(${ItkVtkGlue_USE_FILE})
  set(Glue ItkVtkGlue)
endif()
 
add_executable(Reg_script MACOSX_BUNDLE Reg_script.cxx)
target_link_libraries(Reg_script ITKReview
${Glue}  ${VTK_LIBRARIES} ${ITK_LIBRARIES})


and the error message
1
2
3
2>Reg_script.obj : error LNK2019: unresolved external symbol "void __cdecl Read_Raw_Data(class itk::SmartPointer<class itk::ImageFileReader<class itk::Image<double,2>,class itk::DefaultConvertPixelTraits<double> 
> >,char *)" (?Read_Raw_Data@@YAXV?$SmartPointer@V?$ImageFileReader@V?$Image@N$01@itk@@V?$DefaultConvertPixelTraits@N@2@@itk@@@itk@@PAD@Z) referenced in function _main
2>C:\ITK\scripts\registration\build\Debug\Reg_script.exe : fatal error LNK1120: 1 unresolved externals



I've been searching for a solution, generally this error occurs when a called function has no body, but mine does have a body. I suspect it's a cmake issue, somehow my cmakelists.txt file isn't providing for Reg_script.cxx to talk with IO.h that's my guess anyways. Can anybody help?

Thanks.
Last edited on
generally this error occurs when a called function has no body, but mine does have a body.


Generally this error occurs when the definition of the function is not supplied to the linker. How does Cmakelists.txt account for the compilation of IO.cpp and linking against the corresponding object code?
cire, thanks, that's exactly my question, I don't know! I assume I need to include IO.cpp somewhere in cmakelists.txt but I don't know the proper way.
After a quick google search, it would appear you would add it to line 17 (as one would suspect from looking at it.

add_executable(Reg_script MACOSX_BUNDLE Reg_script.cxx IO.cpp)

http://preetisblog.com/programming/how-to-write-cmakelists-txt
Strange, I think I tried that already as the obvious fix and cmake failed to configure. Let me try again on Monday and see what happens. Maybe there's another error coming across after that is fixed...

Thanks for the link. I must need to work on my googling skills because I searched for some time....
That's got it. A few other minor bugs and it worked. thanks cire.
Topic archived. No new replies allowed.