Building DCMTK 3.5.4 on Mac OS X 10.5.6 as Universal Binary

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
wollet88
Posts: 38
Joined: Fri, 2008-03-28, 11:07

Building DCMTK 3.5.4 on Mac OS X 10.5.6 as Universal Binary

#1 Post by wollet88 »

Dear DCMTK team,

I am trying to build OFFIS DCMTK 3.5.4 on my Intel-based MacBook Pro running Mac OS X 10.5.6. I am using gcc 4.0.1.

After running the "./configure" command, as suggested in another post on this Forum, I added the following switch to the CFLAGS and CXXFLAGS in the /config/Makefile.def: -D_DARWIN_C_SOURCE.

Then, I ran the "make all" and "make install" commands, and the overall build process completed correctly.

Finally, I wanted to modify the build process in order to build a "Universal Binary" version of OFFIS DCMTK 3.5.4.
Here is what I did. I edited the "/config/Makefile.def" and I added the following line:

ARCH = -arch ppc -arch i386 -arch ppc64 -arch x86_64

Then I ran the following commands:

make clean
make all

The build process seems to start in a correct way, and many object files seem to be built correctly. But, at a certain stage I get the following errors:

=====

wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::SetReadlock()':
wldsfs.cc:769: error: cast from 'flock*' to 'int' loses precision
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::ReleaseReadlock()':
wldsfs.cc:824: error: cast from 'flock*' to 'int' loses precision
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::SetReadlock()':
wldsfs.cc:769: error: cast from 'flock*' to 'int' loses precision
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::ReleaseReadlock()':
wldsfs.cc:824: error: cast from 'flock*' to 'int' loses precision
lipo: can't figure out the architecture type of: /var/folders/qA/qAYVTAn-GQaM0hVV5zyqLE+++TI/-Tmp-//ccerp9r4.out
make[2]: *** [wldsfs.o] Error 1
make[1]: *** [libsrc-all] Error 2
make: *** [dcmwlm-all] Error 2

=====

The above errors seem to have to do with the fact that pointers become 64-bit values and casting to "int" (32-bit) may lead to a loss of precision.

Do you have suggestions on how I may solve this problem?
My final objective would be to create an "XCode project" for the OFFIS DCMTK 3.5.4, with appropriate settings to build it as a Universal Binary.

Any hint or suggestion would be greatly appreciated.

Best regards,

Marco.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1444
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg »

The compile error you observe is most likely due to the fact that you modified the compile flags after running configure - the configure script tries to figure out various system properties, and these of course depend on certain compiler settings. Modifying the settings after completion of configure may cause a setting in cfunix.h to become invalid.

Fat binaries may be particularly difficult because you run configure only once yet compile for multiple architectures.

I would suggest that you try setting the CFLAGS, CXXFLAGS and ARCH environment variables before running configure - this should cause your settings to be used during the configure process and to be copied into Makefile.def. Then see if compiling makes any difference - in this particular case SIZEOF_VOID_P in config/include/dcmtk/config/cfunix.h should be defined as 8 after configure, not as 4.

wollet88
Posts: 38
Joined: Fri, 2008-03-28, 11:07

#3 Post by wollet88 »

Hi Marco,

first of all, thanks a lot for your reply and help.

Following your suggestion, I have modified the following lines in the "/config/Makefile.def.in" file:

=====

[...]
ARCH = -arch ppc -arch i386 -arch ppc64 -arch x86_64

[...]
CFLAGS = @CFLAGS@ -D_DARWIN_C_SOURCE
[...]
CXXFLAGS = @CXXFLAGS@ -D_DARWIN_C_SOURCE

=====

Then, I executed the following commands:

make distclean
./configure

At this point, I verified the content of the /config/include/dcmtk/config/cfunix.h file, and it still contained the following line:

=====

[...]
/* The size of a `void *', as computed by sizeof. */
#define SIZEOF_VOID_P 4

=====

In fact, a later execution of the "make all" command returned the same build error as before:

=====

[...]
c++ -DHAVE_CONFIG_H -DNDEBUG -c -I. -I. -I../include -I../../config/include -I../../dcmdata/include -I../../dcmnet/include -I../../ofstd/include -arch ppc -arch i386 -arch ppc64 -arch x86_64 \
-O -I/usr/include/libxml2 -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L -Wall -D_DARWIN_C_SOURCE wldsfs.cc
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::SetReadlock()':
wldsfs.cc:769: error: cast from 'flock*' to 'int' loses precision
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::ReleaseReadlock()':
wldsfs.cc:824: error: cast from 'flock*' to 'int' loses precision
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::SetReadlock()':
wldsfs.cc:769: error: cast from 'flock*' to 'int' loses precision
wldsfs.cc: In member function 'bool WlmDataSourceFileSystem::ReleaseReadlock()':
wldsfs.cc:824: error: cast from 'flock*' to 'int' loses precision
lipo: can't figure out the architecture type of: /var/folders/qA/qAYVTAn-GQaM0hVV5zyqLE+++TI/-Tmp-//ccENlflJ.out
make[2]: *** [wldsfs.o] Error 1
make[1]: *** [libsrc-all] Error 2
make: *** [dcmwlm-all] Error 2

=====

As a further attempt, I tried specifying just "x86_64" as the value for ARCH in "config/Makefile.def.in":

ARCH = -arch x86_64

Then, I executed:

make distclean
./configure

At this point, I verified once again the content of the /config/include/dcmtk/config/cfunix.h file, and once again it still contained the following line:

=====

[...]
/* The size of a `void *', as computed by sizeof. */
#define SIZEOF_VOID_P 4

=====

Then, I executed:

make all

In this case, I obtain a different error:

=====
[...]

c++ -DHAVE_CONFIG_H -DNDEBUG -c -I. -I. -I../include -I../../config/include -I../include -arch x86_64 \
-O -I/usr/include/libxml2 -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L -Wall -D_DARWIN_C_SOURCE tststack.cc
c++ -O -I/usr/include/libxml2 -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L -Wall -D_DARWIN_C_SOURCE -L../libsrc -o tststack tststack.o -lofstd -lpthread
ld warning: in tststack.o, file is not of required architecture
ld warning: in ../libsrc/libofstd.a, file is not of required architecture
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [tststack] Error 1
make[1]: *** [tests-all] Error 2
make: *** [ofstd-all] Error 2

=====

I am a bit new to building C / C++ in Unix-like environments, so I am sorry if some of my questions or mistakes are a bit basic...

Thank you in advance for your help and best regards,

Marco.

wollet88
Posts: 38
Joined: Fri, 2008-03-28, 11:07

#4 Post by wollet88 »

Hi to everybody,

I think I figured it out, looking at how the "configure" script compiles test config files and how compilation flags are read from environment variables.

So, here is what I finally did, which seems to lead to a successful "Universal Binary" build of the DCMTK:

1 - I left all files from the DMCTK 3.5.4 source distribution unchanged.

2 - I created a "dicom" subfolder in my home directory (not sure if this step is mandatory)

3 - I launched the following command:

env ARCH='-arch ppc -arch i386 -arch ppc64 -arch x86_64' CFLAGS='-D_DARWIN_C_SOURCE -arch ppc -arch i386 -arch ppc64 -arch x86_64' CXXFLAGS='-D_DARWIN_C_SOURCE -arch ppc -arch i386 -arch ppc64 -arch x86_64' ./configure --prefix=$HOME/dicom

4 - I launched the following command:

make all

5 - I launched the following command:

make install

That's it. Now in my ~/dicom folder I have a "Universal Binary" version of all DCMTK utilities. Also, all "*.a" static libraries compiled under the DCMTK source directory should be in "Universal Binary" format.

I hope the above explanation may help other Mac DCMTK users.

Best regards,

Marco.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1444
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#5 Post by Marco Eichelberg »

Thanks for your post. This is what I tried to explain (of course in much less detail than provided in your post that will certainly be helpful for other Mac OS X users) when I suggested that you set environment variables prior to running configure. Good to know it still works - the ARCH stuff was originally included in the DCMTK makefile structure for NeXTStep 3.3 some 13 or 14 years ago. As you may know, NeXTStep is kind of a grandfather of current MacOS X, and already supported fat binaries with gcc's -arch command line option.

ali.m.habib
Posts: 85
Joined: Sun, 2010-12-26, 17:34

#6 Post by ali.m.habib »

wollet88 wrote:Hi to everybody,

I think I figured it out, looking at how the "configure" script compiles test config files and how compilation flags are read from environment variables.

So, here is what I finally did, which seems to lead to a successful "Universal Binary" build of the DCMTK:

1 - I left all files from the DMCTK 3.5.4 source distribution unchanged.

2 - I created a "dicom" subfolder in my home directory (not sure if this step is mandatory)

3 - I launched the following command:

env ARCH='-arch ppc -arch i386 -arch ppc64 -arch x86_64' CFLAGS='-D_DARWIN_C_SOURCE -arch ppc -arch i386 -arch ppc64 -arch x86_64' CXXFLAGS='-D_DARWIN_C_SOURCE -arch ppc -arch i386 -arch ppc64 -arch x86_64' ./configure --prefix=$HOME/dicom

4 - I launched the following command:

make all

5 - I launched the following command:

make install

That's it. Now in my ~/dicom folder I have a "Universal Binary" version of all DCMTK utilities. Also, all "*.a" static libraries compiled under the DCMTK source directory should be in "Universal Binary" format.

I hope the above explanation may help other Mac DCMTK users.

Best regards,

Marco.
when write the following in mac terminal give me env: ./configure: No such file or directory

svps-Mac:~ abduljaleelmalik$ env ARCH='-arch ppc -arch i386 -arch ppc64 -arch x86_64' CFLAGS='-D_DARWIN_C_SOURCE -arch ppc -arch i386 -arch ppc64 -arch x86_64' CXXFLAGS='-D_DARWIN_C_SOURCE -arch ppc -arch i386 -arch ppc64 -arch x86_64' ./configure --prefix=$HOME/dicom



any suggestion plaese

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest