[Insight-users] Compiling ITK4 in 32 bit mode on 64 bit linux

Luis Ibanez luis.ibanez at kitware.com
Sat Feb 19 15:47:15 EST 2011


Hi Andriy,

------------------------------------------------------------------------------
On Thu, Feb 17, 2011 at 2:31 PM, Andriy Fedorov <fedorov at bwh.harvard.edu> wrote:
> 1) is there a set of specific instructions on building ITK4 on 32 bit
> platform? (I haven't found any, and I have problems compiling it, see
> below)
-----------------------------------------------------------


Note that what you are asking is not

    "How to build ITK in a 32-bits platform"

but

    "How to cross-compile ITK for a 32-bit
     platform target in a 64-bit platform host"

which is quite different.


Building ITK natively in a 32-bit platform is
trivial and can be done with the traditional:

                      mkdir ITKbin
                      cd ITKbin
                      cmake        ~/src/ITK
                      make


While,
cross-compiling it for a 32-bits target platform
in a 64-bits host requires the following steps:


A)   Install the libraries for 32-bits:

A.1)  sudo    apt-get  install    libc6-dev-i386


Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  gcc-4.4-multilib gcc-multilib lib32gcc1 lib32gomp1 libc6-i386
Suggested packages:
  lib32mudflap0
The following NEW packages will be installed:
  gcc-4.4-multilib gcc-multilib lib32gcc1 lib32gomp1 libc6-dev-i386 libc6-i386
0 upgraded, 6 newly installed, 0 to remove and 1 not upgraded.
Need to get 7,599kB of archives.
After this operation, 18.5MB of additional disk space will be used.


A.2)    sudo apt-get install g++-4.4-multilib

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  lib32stdc++6
Suggested packages:
  lib32stdc++6-4.4-dbg
The following NEW packages will be installed:
  g++-4.4-multilib lib32stdc++6
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 1,355kB of archives.
After this operation, 6,144kB of additional disk space will be used.



2) Run ccmake

                      Add  the flag "-m32" to:

CMAKE_CXX_FLAGS
CMAKE_C_FLAGS
CMAKE_EXE_LINKER_FLAGS
CMAKE_REQUIRED_FLAGS


The best way is to do this from the command line:

ccmake ~/src/ITK \
-DCMAKE_CXX_FLAGS:STRING=-m32  \
-DCMAKE_C_FLAGS:STRING=-m32 \
-DCMAKE_EXE_LINKER_FLAGS:STRING=-m32 \
-DCMAKE_REQUIRED_FLAGS:STRING=-m32


"c" to configure
"g" to generate


3) Finally do

                               make


-----------------------------------------------------
>
> 2) are there any 32-bit machines on ITK4 dashboard?
>
-----------------------------------------------------

Yes:

See for example:

1)  zion.kitware :  Ubuntu 10.10  - 32 bits

2)  thurmite.kitware : Darwin - 32 bits

http://www.cdash.org/CDash/index.php?project=Insight&filtercount=1&showfilters=1&field1=site/string&compare1=63&value1=zion

http://www.cdash.org/CDash/index.php?project=Insight&filtercount=1&showfilters=1&field1=site/string&compare1=63&value1=thurmite


But note that this are "native 32-bits" machines.

While, what you are asking for,
is "how to cross-compile ITK for 32-bits in a 64-bits machine".


If what you wanted is to replicate a build problem in
a native 32-bits machine, it is a lot simpler to use a
VirtualBox appliance that has a 32-bits machine
system installed.


For example,
You could use the one that we have at:

          http://midas.kitware.com/item/view/450

If you install VirtualBox in your 64-bits machine,
you will be able to use this Virtual Appliance with
a 32-bits native system.


---------------------------------------------------
> The long story is below ... All I wanted to do is to test some
> functionality of 3D Slicer, since we found some issues on 32-bit
> build.
>
------------------------------------------------------

What was the issue in Slicer ?

------------------------------------------------------
>
> I am trying to compile current checkout of ITK4 on Ubuntu 10.04 x64 in
> 32-bit mode.
>
> To do this, I installed gcc-multilib support, and specified -m32 flag
> for CC and CXX.
>
> My first attempt to compile resulted in the following error:
> /home/andrey/local/src/ITK/Code/Common/itkChainCodePath2D.cxx:18:
> /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/emmintrin.h:32:3: error:
> #error "SSE2 instruction set not enabled"
>
> Following some advice from google, I added flags -msse2 and -msse4.
> This resulted in the following error:
>
> In file included from /home/andrey/local/src/ITK/Code/Common/itkMath.h:32,
>                 from
> /home/andrey/local/src/ITK/Testing/Code/Common/itkMathTest.cxx:22:
> /home/andrey/local/src/ITK/Code/Common/itkMathDetail.h: In function
> ‘itk::int64_t itk::Math::Detail::RoundHalfIntegerToEven_64(double)’:
> /home/andrey/local/src/ITK/Code/Common/itkMathDetail.h:280: error:
> ‘_mm_cvtsd_si64’ was not declared in this scope
>
-------------------------------------------------------------


The reason why you are seeing these errors
is that the "SSE" capabilities of the machine
are being tests with a "TRY_COMPILE", at
configuration time, in your case, in the first
run of ccmake.

However, to be consistent with your "32-bits"
build, those try-compiles should be aware
that you are building for that 32-bits platform.

The way to inform CMake of that fact, is by
setting the variable:

          CMAKE_REQUIRED_FLAGS

to include the "-m32" flag as well, such as in:

-DCMAKE_REQUIRED_FLAGS:STRING=-m32


In this way, the TRY_COMPILES will be made
aware that they should evaluate the characteristics
of the system as a 32-bits machine.


Otherwise, the try_compiles are made "for your
64-bits" machine, and then the results are applied
to you "32-bits build" obviously resulting in conflicts.



     Luis


---------------------------------------------------
> thanks
>
> --
> Andriy Fedorov, Ph.D.
>
> Research Fellow
> Brigham and Women's Hospital
> Harvard Medical School
> 75 Francis Street
> Boston, MA 02115 USA
> fedorov at bwh.harvard.edu
> (617) 525-6258 (office)
> _____________________________________


More information about the Insight-users mailing list