Linking ITK and QT (Ubuntu)

Hi
I’ve been using ITK and Qt for a long time on windows. I am now trying to compile my soft on ubuntu 18.04 . ITK compiles well, the tests are OK. When linking my soft, I get the errors below. Has someone any idea ?
Thank you

/usr/local/lib/libITKCommon-5.1.a(itkNumberToString.cxx.o): In function itk::NumberToString<double>::operator()[abi:cxx11](double)': itkNumberToString.cxx:(.text+0x29): undefined reference todouble_conversion::DoubleToStringConverter::EcmaScriptConverter()’
itkNumberToString.cxx:(.text+0x5a):Makefile:493: recipe for target ‘…/magicsIMNC’ failed
undefined reference to double_conversion::DoubleToStringConverter::ToShortestIeeeNumber(double, double_conversion::StringBuilder*, double_conversion::DoubleToStringConverter::DtoaMode) const' /usr/local/lib/libITKCommon-5.1.a(itkNumberToString.cxx.o): In functionitk::NumberToString::operator()abi:cxx11’:
itkNumberToString.cxx:(.text+0x28a): undefined reference to double_conversion::DoubleToStringConverter::EcmaScriptConverter()' itkNumberToString.cxx:(.text+0x2d0): undefined reference todouble_conversion::DoubleToStringConverter::ToShortestIeeeNumber(double, double_conversion::StringBuilder*, double_conversion::DoubleToStringConverter::DtoaMode) const’
/usr/local/lib/libITKCommon-5.1.a(itkDynamicLoader.cxx.o): In function itk::DynamicLoader::OpenLibrary(char const*)': itkDynamicLoader.cxx:(.text+0xc8): undefined reference toitksys::DynamicLoader::OpenLibrary(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’
/usr/local/lib/libITKCommon-5.1.a(itkDynamicLoader.cxx.o): In function itk::DynamicLoader::GetSymbolAddress(void*, char const*)': itkDynamicLoader.cxx:(.text+0x213): undefined reference toitksys::DynamicLoader::GetSymbolAddress(void*, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’
/usr/local/lib/libITKCommon-5.1.a(itkDynamicLoader.cxx.o): In function itk::DynamicLoader::CloseLibrary(void*)': itkDynamicLoader.cxx:(.text+0x191): undefined reference toitksys::DynamicLoader::CloseLibrary(void*)’
/usr/local/lib/libITKCommon-5.1.a(itkDynamicLoader.cxx.o): In function itk::DynamicLoader::LastError()': itkDynamicLoader.cxx:(.text+0x301): undefined reference toitksys::DynamicLoader::LastError()’
/usr/local/lib/libITKCommon-5.1.a(itkDirectory.cxx.o): In function itk::Directory::~Directory()': itkDirectory.cxx:(.text+0x24): undefined reference toitksys::Directory::~Directory()’
/usr/local/lib/libITKCommon-5.1.a(itkDirectory.cxx.o): In function itk::Directory::Directory()': itkDirectory.cxx:(.text+0x8b): undefined reference toitksys::Directory::Directory()’
/usr/local/lib/libITKCommon-5.1.a(itkDirectory.cxx.o): In function itk::Directory::Load(char const*)': itkDirectory.cxx:(.text+0x134): undefined reference toitksys::Directory::Load(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’
/usr/local/lib/libITKCommon-5.1.a(itkDirectory.cxx.o): In function itk::Directory::PrintSelf(std::ostream&, itk::Indent) const': itkDirectory.cxx:(.text+0x26a): undefined reference toitksys::Directory::GetPath() const’
itkDirectory.cxx:(.text+0x2d5): undefined reference to itksys::Directory::GetNumberOfFiles() const' itkDirectory.cxx:(.text+0x337): undefined reference toitksys::Directory::GetFile(unsigned long) const’
/usr/local/lib/libITKCommon-5.1.a(itkDirectory.cxx.o): In function itk::Directory::GetNumberOfFiles()': itkDirectory.cxx:(.text+0x205): undefined reference toitksys::Directory::GetNumberOfFiles() const’
/usr/local/lib/libITKCommon-5.1.a(itkDirectory.cxx.o): In function itk::Directory::GetFile(unsigned int)': itkDirectory.cxx:(.text+0x217): undefined reference toitksys::Directory::GetFile(unsigned long) const’
collect2: error: ld returned 1 exit status
make: *** […/yyy] Error 1
23:00:12: Le processus “/usr/bin/make” s’est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet magicsIMNC (kit : Desktop Qt 5.12.5 GCC 64bit)
When executing step “Make”

The command is
g++ -Wl,-O1 -o …/yyy list-of-myfiles.o -L/usr/local/lib -litkdouble-conversion-5.1 -litknetlib-5.1 -lITKOptimizers-5.1 -litkvnl_algo-5.1 -litkvnl-5.1 -lITKVNLInstantiation-5.1 -lITKOptimizersv4-5.1 -lITKStatistics-5.1 -litkv3p_netlib-5.1 -litksys-5.1 -lITKCommon-5.1 -ldl -lpthread /home/xxx/Qt/5.12.5/gcc_64/lib/libQt5PrintSupport.so /home/xxx/Qt/5.12.5/gcc_64/lib/libQt5Widgets.so /home/xxx/Qt/5.12.5/gcc_64/lib/libQt5Gui.so /home/xxx/Qt/5.12.5/gcc_64/lib/libQt5Concurrent.so /home/xxx/Qt/5.12.5/gcc_64/lib/libQt5Core.so -lGL

You could take a look at this discussion, as well as this PR which has more references to code.

Thank you for your answer.

  I saw this topic but my problem is not the include file

“double-conversion.h” at the compilation step. My problem is at
the linking step : all the itk libraries are built without any
problem, the itk tests are OK, but when linking my qt project
with the itk libraries, I got the errors listed in my previous
post.

Hi @FBT, you are not using CMake.
From where did you get the list of ITK libraries that you need? Maybe you are missing some? Have you tried to link all of them? Did you compile ITK with default options, or used any SYSTEM library?
The Common module seems to have more dependencies that you have used. See its itk-module.cmake

if( Module_ITKTBB )
  set(ITKCOMMON_TBB_DEPENDS ITKTBB)
endif()

itk_module(ITKCommon
  ENABLE_SHARED
  DEPENDS
    ITKEigen3
    ITKKWIML
    ${ITKCOMMON_TBB_DEPENDS}
  PRIVATE_DEPENDS
    ITKDoubleConversion
  COMPILE_DEPENDS
    ITKKWSys
    ITKVNLInstantiation
  TEST_DEPENDS
    ITKTestKernel
    ITKMesh
    ITKImageIntensity
    ITKIOImageBase
  DESCRIPTION
    "${DOCUMENTATION}"
)

I compiled ITK with cmake-gui 3.10.2 . I kept the default
options, I just add Module_ITKreview .

  My own program is compiled with Qt-creator and is configured in a

.pro file. Yes, I tried to include all libraries, in that case I
get other errors (listed below). I 've done such a way on windows
for a long time and everything works fine.

      /usr/local/lib/libITKOptimizers-5.1.a(itkMultipleValuedNonLinearVnlOptimizer.cxx.o):

In function
`itk::MultipleValuedNonLinearVnlOptimizer::PrintSelf(std::ostream&,
itk::Indent) const’:

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text+0x4d):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array
const&)’

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text+0xbb):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array2D
const&)’

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text+0x129):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array
const&)’

      /usr/local/lib/libITKOptimizers-5.1.a(itkMultipleValuedNonLinearVnlOptimizer.cxx.o):

In function
`itk::MultipleValuedNonLinearVnlOptimizer::MultipleValuedNonLinearVnlOptimizer()’:

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text+0x569):

undefined reference to `itk::Command::Command()’

      /usr/local/lib/libITKOptimizers-5.1.a(itkMultipleValuedNonLinearVnlOptimizer.cxx.o):

In function
`itk::ReceptorMemberCommanditk::MultipleValuedNonLinearVnlOptimizer::~ReceptorMemberCommand()’:

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text._ZN3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEED2Ev[_ZN3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEED5Ev]+0xf):

undefined reference to `itk::Command::~Command()’

      /usr/local/lib/libITKOptimizers-5.1.a(itkMultipleValuedNonLinearVnlOptimizer.cxx.o):

In function
`itk::ReceptorMemberCommanditk::MultipleValuedNonLinearVnlOptimizer::~ReceptorMemberCommand()’:

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text._ZN3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEED0Ev[_ZN3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEED5Ev]+0x13):

undefined reference to `itk::Command::~Command()’

      /usr/local/lib/libITKOptimizers-5.1.a(itkMultipleValuedNonLinearVnlOptimizer.cxx.o):

In function
`itk::ReceptorMemberCommanditk::MultipleValuedNonLinearVnlOptimizer::CreateAnother()
const’:

      itkMultipleValuedNonLinearVnlOptimizer.cxx:(.text._ZNK3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEE13CreateAnotherEv[_ZNK3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEE13CreateAnotherEv]+0xdb):

undefined reference to `itk::Command::Command()’

      /usr/local/lib/libITKOptimizers-5.1.a(itkMultipleValuedNonLinearVnlOptimizer.cxx.o):(.data.rel.ro._ZTIN3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEEE[_ZTIN3itk21ReceptorMemberCommandINS_35MultipleValuedNonLinearVnlOptimizerEEE]+0x10):

undefined reference to `typeinfo for itk::Command’

      /usr/local/lib/libITKOptimizers-5.1.a(itkOptimizer.cxx.o):

In function `itk::Optimizer::PrintSelf(std::ostream&,
itk::Indent) const’:

      itkOptimizer.cxx:(.text+0x11fd):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array
const&)’

      itkOptimizer.cxx:(.text+0x1266):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array
const&)’

      itkOptimizer.cxx:(.text+0x13e7):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array
const&)’

      itkOptimizer.cxx:(.text+0x1453):

undefined reference to `std::ostream& itk::operator<<
(std::ostream&, itk::Array
const&)’

      /usr/local/lib/libitkvnl_algo-5.1.a(vnl_levenberg_marquardt.cxx.o):

In function `vnl_levenberg_marquardt::lmdif_lsqfun(long*, long*,
double*, double*, long*, void*)’:

      vnl_levenberg_marquardt.cxx:(.text+0x9f):

undefined reference to
`vnl_vector_ref::vnl_vector_ref(unsigned int,
double*)’

      vnl_levenberg_marquardt.cxx:(.text+0xb8):

undefined reference to
`vnl_vector_ref::vnl_vector_ref(unsigned int,
double*)’

      vnl_levenberg_marquardt.cxx:(.text+0x109):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      vnl_levenberg_marquardt.cxx:(.text+0x111):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      vnl_levenberg_marquardt.cxx:(.text+0x2d7):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      vnl_levenberg_marquardt.cxx:(.text+0x2df):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      /usr/local/lib/libitkvnl_algo-5.1.a(vnl_levenberg_marquardt.cxx.o):

In function `vnl_levenberg_marquardt::lmder_lsqfun(long*, long*,
double*, double*, double*, long*, long*, void*)’:

      vnl_levenberg_marquardt.cxx:(.text+0x36a):

undefined reference to
`vnl_vector_ref::vnl_vector_ref(unsigned int,
double*)’

      vnl_levenberg_marquardt.cxx:(.text+0x386):

undefined reference to
`vnl_vector_ref::vnl_vector_ref(unsigned int,
double*)’

      vnl_levenberg_marquardt.cxx:(.text+0x55b):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      vnl_levenberg_marquardt.cxx:(.text+0x567):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      vnl_levenberg_marquardt.cxx:(.text+0x69a):

undefined reference to `v3p_netlib_fdjac2_’

      vnl_levenberg_marquardt.cxx:(.text+0xa6d):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      vnl_levenberg_marquardt.cxx:(.text+0xa79):

undefined reference to
`vnl_vector_ref::~vnl_vector_ref()’

      /usr/local/lib/libitkvnl_algo-5.1.a(vnl_levenberg_marquardt.cxx.o):

In function
`vnl_levenberg_marquardt::minimize_without_gradient(vnl_vector&)’:

      vnl_levenberg_marquardt.cxx:(.text+0xec6):

undefined reference to `v3p_netlib_lmdif_’

      /usr/local/lib/libitkvnl_algo-5.1.a(vnl_levenberg_marquardt.cxx.o):

In function
`vnl_levenberg_marquardt::minimize_using_gradient(vnl_vector&)’:

      vnl_levenberg_marquardt.cxx:(.text+0x12b7):

undefined reference to `v3p_netlib_lmder_’

      /usr/local/lib/libitkvnl_algo-5.1.a(vnl_levenberg_marquardt.cxx.o):

In function `vnl_levenberg_marquardt::get_JtJ()’:

      vnl_levenberg_marquardt.cxx:(.text+0x19ca):

undefined reference to
`vnl_fastops::AtA(vnl_matrix&,
vnl_matrix const&)’

      vnl_levenberg_marquardt.cxx:(.text+0x19ec):

undefined reference to `vnl_vector::vnl_vector(unsigned
long)’

      vnl_levenberg_marquardt.cxx:(.text+0x1ac0):

undefined reference to `vnl_vector::~vnl_vector()’

      vnl_levenberg_marquardt.cxx:(.text+0x1b39):

undefined reference to `vnl_vector::~vnl_vector()’

      /usr/local/lib/libitkvnl_algo-5.1.a(vnl_levenberg_marquardt.cxx.o):

In function `_GLOBAL__sub_I_vnl_levenberg_marquardt.cxx’:

      vnl_levenberg_marquardt.cxx:(.text.startup+0x2f):

undefined reference to `v3p_netlib_initialize’

      collect2: error:

ld returned 1 exit status

Are you sure those ITK libraries are up-to-date? Could you remove them all and recompile and reinstall ITK? Or maybe install ITK in another location and try from there? Maybe the order of the ITK libraries play a role?
I am not familiar with Qt .pro projects, but there a lot of other projects using Qt and ITK (using CMake) with no issues. I’d recommend to start in a clean state with ITK, and sorry for the long-shot suggestions, not familiar with .pro files, I would finally recommend you try a toy project with CMake, Qt and ITK to check if it works.

1 Like

Thank you for the suggestions. I download and compiled ITK a few
days ago so I’m sure they are up-to-date. I tried several times,
with and without ITKreview. I develop the project on windows using
Qtcreator and I would like to use the same tools on both systems,
it works on windows, it should on ubuntu.