[ITK-users] stand-alone lib -- ITKApps/ITKFilterLib

Dženan Zukić dzenanz at gmail.com
Wed Mar 23 10:39:25 EDT 2016


Hi Robert,

BUILD_SHARED_LIBS OFF is the crucial setting. You can keep the rest of
options on defaults.

Your CMake code looks OK. You should execute the following from your folder:
cmake .
make

During CMake step you should configure options (point to the itk-build
folder which was configured with BUILD_SHARED_LIBS OFF). Afterwards, do not
invoke g++ directly - invoke make, which supplies correct include
directories and link libraries so you don't run into a thousand errors.

Regards,
Dženan

On Tue, Mar 22, 2016 at 6:25 AM, <Robert.Atwood at diamond.ac.uk> wrote:

> Hi,
> Thanks, Dženan, for the hint. But, does anyone have specific information
> on exactly which options to set in each of: the ITK cmake options; and the
> project cmake options, or the plain g++ for building an external program to
> link to the library, for this to work ? There appear to be a few that might
> be related to this. Because, so far, simply changing the build options of
> the ITK installation didn’t work. See below for even more details .
>
> Thanks
>
> Robert
>
>
>
>
>
>
>
> Options selected in  the project:
>
> ITK_DIR
> /dls_sw/apps/itk/itk-master-static/lib/cmake/ITK-4.10
>
>
>
>
>
>
>
> In the ITK with installation to itk-master-static:
>
> I have tried some combinations of these options but, you know, it takes a
> while to rebuild ITK even though the computer is pretty good.
>
>
>
> BUILD_POSITION_DEPENDENT_CODE    OFF  (I don’t think this should be ON
> because that really wouldn’t work? )
>
> BUILD_SHARED_LIBS                OFF (or ON)
>
> CMAKE_CXX_FLAGS                  -fPIC (or default)
>
> CMAKE_EXE_LINKER_FLAGS           -fPIC (or default)
>
> CMAKE_STATIC_LINKER_FLAGS  (should this be set too? )
>
>
>
>
>
>
>
> The CMakeLists in the project file – only small modification from the
> original to ‘BUILD_OUTSIDE_INSIGHT_APPICATIONS’. The project builds using
> the Cmake makefile,  producing the library and the executable
>
> But trying to build either the ‘main’ procedure provided with linking to
> that library, or even simplifying the ‘main’ to do virtually nothing except
> instantiate the object, results in 1000 error messages of ‘undefined
> symbols’
>
>
>
>   1 PROJECT(Example_ITKFilterLib)
>
>   2
>
>   3 #REMOVED 'IF (BUILD_OUTSIDE_INSIGHT_APPLICATIONS)'
>
>   4
>
>   5   FIND_PACKAGE(ITK)
>
>   6   IF(ITK_FOUND)
>
>   7     INCLUDE(${ITK_USE_FILE})
>
>   8   ELSE(ITK_FOUND)
>
>   9     MESSAGE(FATAL_ERROR
>
> 10             "Cannot build ITKApps without ITK.  Please set ITK_DIR.")
>
> 11   ENDIF(ITK_FOUND)
>
> 12
>
> 13 #REMOVED 'ENDIF(BUILD_OUTSIDE_INSIGHT_APPLICATIONS)'
>
> 14
>
> 15 ADD_LIBRARY(Example_ITKFilterLib ITKFilterLib.cxx )
>
> 16 INSTALL_TARGETS(/lib Example_ITKFilterLib)
>
> 17 TARGET_LINK_LIBRARIES(Example_ITKFilterLib ${ITK_LIBRARIES})
>
> 18
>
> 19 ADD_EXECUTABLE(Example_ITKFilterLibTest ITKFilterLibTest.cxx )
>
> 20 INSTALL_TARGETS(/bin Example_ITKFilterLibTest)
>
> 21 TARGET_LINK_LIBRARIES(Example_ITKFilterLibTest Example_ITKFilterLib)
>
>
>
>
>
> build]$ ls -l
>
> total 2508
>
> -rw-rw-r-- 1 kny48981 kny48981   14393 Mar 22 10:02 CMakeCache.txt
>
> drwxrwxr-x 6 kny48981 kny48981    4096 Mar 22 10:05 CMakeFiles
>
> -rwxrwxr-x 1 kny48981 kny48981 1417263 Mar 22 10:05
> Example_ITKFilterLibTest
>
> drwxrwxr-x 2 kny48981 kny48981    4096 Mar 22 10:02
> ITKIOFactoryRegistration
>
> -rw-rw-r-- 1 kny48981 kny48981    7933 Mar 22 10:02 Makefile
>
> -rw-rw-r-- 1 kny48981 kny48981 1092874 Mar 22 10:05
> libExample_ITKFilterLib.a
>
>
>
>
>
>
>
> build]$ g++ -o testcomp ../ITKFilterLib/ITKFilterLibTest.cxx -I
> ../ITKFilterLib -L . -l Example_ITKFilterLib >& out &
>
>
>
> … generates 1100 messages …
>
>
>
>
>
>    1 ./libExample_ITKFilterLib.a(ITKFilterLib.o): In function
> `itk::MemoryAllocationError::MemoryAllocationError(std::basic_string<char,
> std::char_traits<char>, std::allocat
>
>    2
> ITKFilterLib.cxx:(.text._ZN3itk21MemoryAllocationErrorC2ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC5ERKSsjS2_S2_]+0x39):
> undefined reference to `itk::ExceptionObject:
>
>>
> 1106
> ITKFilterLib.cxx:(.text._ZNK3itk12NeighborhoodIPfLj3ENS_21NeighborhoodAllocatorIS1_EEE9PrintSelfERSoNS_6IndentE[itk::Neighborhood<float*,
> 3u, itk::NeighborhoodAllocato
>
> 1107 collect2: ld returned 1 exit status
>
>
>
>
>
> Minimal example main:
>
>
>
>   1 #include "ITKFilterLib.h"
>
>   2 int main(int, char **) {
>
>   3   int inputDimSize[3];
>
>   4   float inputOrigin[3];
>
>   5   float inputSpacing[3];
>
>   6   inputDimSize[0] = 5;
>
>   7   inputDimSize[1] = 5;
>
>   8   inputDimSize[2] = 5;
>
>   9   inputOrigin[0] = 0;
>
> 10   inputOrigin[1] = 0;
>
> 11   inputOrigin[2] = 0;
>
> 12   inputSpacing[0] = 1;
>
> 13   inputSpacing[1] = 1;
>
> 14   inputSpacing[2] = 1;
>
> 15
>
> 16   itkFilterLib filter(inputDimSize, inputOrigin, inputSpacing);
>
> 17   return (true);
>
> 18 }
>
>
>
> g++ -o testmin minimal_example.cxx -I ../ITKFilterLib -L . -l
> Example_ITKFilterLib >& out
>
>
>
>
>
> Same output AFAICT:
>
>
>
>
>
>    1 ./libExample_ITKFilterLib.a(ITKFilterLib.o): In function
> `itk::MemoryAllocationError::MemoryAllocationError(std::basic_string<char,
> std::char_traits<char>, std::alloca
>
>    2
> ITKFilterLib.cxx:(.text._ZN3itk21MemoryAllocationErrorC2ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC5ERKSsjS2_S2_]+0x39):
> undefined reference to `itk::ExceptionObject:
>
> ….
>
>
>
> *From:* Dženan Zukić [mailto:dzenanz at gmail.com]
> *Sent:* 21 March 2016 20:21
> *To:* Atwood, Robert (DLSLtd,RAL,SCI)
> *Cc:* Insight-users
> *Subject:* Re: [ITK-users] stand-alone lib -- ITKApps/ITKFilterLib
>
>
>
> Hi Robert,
>
>
>
> maybe you need to link to ITK statically? To accomplish this you probably
> need to build ITK as static libraries (it is a configuration option in
> CMake).
>
>
>
> Regards,
>
> Dženan
>
>
>
> On Mon, Mar 21, 2016 at 12:50 PM, <Robert.Atwood at diamond.ac.uk> wrote:
>
> Hi,
> This example, ITKApps/ITKFilterLib, appears to be an example of what I
> want to do , bundle or encapsulate  a specific ITK-based filter into a
> library so that another program may just call it without having to have the
> ITK source installation available.
> However, a basic test for me is not working.
>
> I just tried to compile the test example from command line after building
> the library with Cmake as usual. I get hundreds of 'undefined reference',
> as if I have to link with all the ITK libs anyways.
> Am I missing something?
> Thanks
>
>
>
>
> g++ -o testcomp ../ITKFilterLib/ITKFilterLibTest.cxx -I ../ITKFilterLib/
> -L . -l Example_ITKFilterLib
>
>
> First few lines of output:
>
> ./libExample_ITKFilterLib.a(ITKFilterLib.o): In function
> `itk::MemoryAllocationError::MemoryAllocationError(std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const&, unsigned int,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> const&, std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > const&)':
> ITKFilterLib.cxx:(.text._ZN3itk21MemoryAllocationErrorC2ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC5ERKSsjS2_S2_]+0x39):
> undefined reference to
> `itk::ExceptionObject::ExceptionObject(std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const&, unsigned int,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >
> const&, std::basic_string<char, std::char_trait
> ITKFilterLib.cxx:(.text._ZN3itk21MemoryAllocationErrorC2ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC5ERKSsjS2_S2_]+0x44):
> undefined reference to `vtable for itk::MemoryAllocationError'
> ./libExample_ITKFilterLib.a(ITKFilterLib.o): In function
> `itk::ProcessAborted::ProcessAborted(char const*, unsigned int)':
> ITKFilterLib.cxx:(.text._ZN3itk14ProcessAbortedC2EPKcj[_ZN3itk14ProcessAbortedC5EPKcj]+0x33):
> undefined reference to `itk::ExceptionObject::ExceptionObject(char const*,
> unsigned int, char const*, char const*)'
> ITKFilterLib.cxx:(.text._ZN3itk14ProcessAbortedC2EPKcj[_ZN3itk14ProcessAbortedC5EPKcj]+0x3e):
> undefined reference to `vtable for itk::ProcessAborted'
> ITKFilterLib.cxx:(.text._ZN3itk14ProcessAbortedC2EPKcj[_ZN3itk14ProcessAbortedC5EPKcj]+0x4f):
> undefined reference to `itk::ExceptionObject::SetDescription(char const*)'
> ITKFilterLib.cxx:(.text._ZN3itk14ProcessAbortedC2EPKcj[_ZN3itk14ProcessAbortedC5EPKcj]+0x62):
> undefined reference to `itk::ExceptionObject::~ExceptionObject()'
>
>
>
> This is on a Linux Red Hat with ITK git master today (March 21 2016)
>
> cmake --version
> cmake version 2.8.12.2
>
> /proc/version:
>
> Linux version 2.6.32-573.18.1.el6.x86_64 (
> mockbuild at x86-010.build.bos.redhat.com) (gcc version 4.4.7 20120313 (Red
> Hat 4.4.7-16) (GCC) ) #1 SMP Wed Jan 6 11:20:49 EST 2016
>
>
>
> --
> This e-mail and any attachments may contain confidential, copyright and or
> privileged material, and are for the use of the intended addressee only. If
> you are not the intended addressee or an authorised recipient of the
> addressee please notify us of receipt by returning the e-mail and do not
> use, copy, retain, distribute or disclose the information in or attached to
> the e-mail.
> Any opinions expressed within this e-mail are those of the individual and
> not necessarily of Diamond Light Source Ltd.
> Diamond Light Source Ltd. cannot guarantee that this e-mail or any
> attachments are free from viruses and we cannot accept liability for any
> damage which you may sustain as a result of software viruses which may be
> transmitted in or with the message.
> Diamond Light Source Limited (company no. 4375679). Registered in England
> and Wales with its registered office at Diamond House, Harwell Science and
> Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
>
>
>
>
>
> --
>
> This e-mail and any attachments may contain confidential, copyright and or
> privileged material, and are for the use of the intended addressee only. If
> you are not the intended addressee or an authorised recipient of the
> addressee please notify us of receipt by returning the e-mail and do not
> use, copy, retain, distribute or disclose the information in or attached to
> the e-mail.
> Any opinions expressed within this e-mail are those of the individual and
> not necessarily of Diamond Light Source Ltd.
> Diamond Light Source Ltd. cannot guarantee that this e-mail or any
> attachments are free from viruses and we cannot accept liability for any
> damage which you may sustain as a result of software viruses which may be
> transmitted in or with the message.
> Diamond Light Source Limited (company no. 4375679). Registered in England
> and Wales with its registered office at Diamond House, Harwell Science and
> Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160323/c3811662/attachment.html>


More information about the Insight-users mailing list