[Insight-users] compile problem on OpenBSD

Amit Kulkarni amitkulz at gmail.com
Tue Oct 5 19:37:31 EDT 2010


Hi Luis,

I got help from Ian Scott from the vxl-users mailing list and found
out the things stopping me from doing vxl-specific build on OpenBSD. I
folded in his patch and uploaded the changes by testing it on FreeBSD.
Here is the CDash output from the tested build which doesn't include
the mallinfo changes but the vxl specific changes for OpenBSD on OTB
trunk
http://dash.orfeo-toolbox.org/buildSummary.php?buildid=32148
and here's the conversation on vxl-users
http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTi%3DQ2U158XqRTf2%2BvtCe-bFw4g4kf3qvxS2mhUtx%40mail.gmail.com&forum_name=vxl-users

I hope Ian integrates his patch and the swap32()/swap64() problem into
next version of Vxl so that Vxl and ITK continue to run on OpenBSD.

I have run into mallinfo problem which you guys might be able to help
to doublecheck.

[ 44%] Building CXX object
Code/Common/CMakeFiles/ITKCommon.dir/itkMemoryUsageObserver.cxx.o
In file included from
/home/amit/Desktop/InsightToolkit-3.20.0/Code/Common/itkMemoryUsageObserver.cxx:46:
/usr//include/malloc.h:4:2: warning: #warning "<malloc.h> is obsolete,
use <stdlib.h>"
/home/amit/Desktop/InsightToolkit-3.20.0/Code/Common/itkMemoryUsageObserver.cxx:
In member function 'virtual long unsigned int
itk::MallinfoMemoryUsageObserver::GetMemoryUsage()':
/home/amit/Desktop/InsightToolkit-3.20.0/Code/Common/itkMemoryUsageObserver.cxx:422:
error: variable 'itk::mallinfo minfo' has initializer but incomplete
type
/home/amit/Desktop/InsightToolkit-3.20.0/Code/Common/itkMemoryUsageObserver.cxx:422:
error: invalid use of incomplete type 'struct itk::mallinfo'
/home/amit/Desktop/InsightToolkit-3.20.0/Code/Common/itkMemoryUsageObserver.cxx:422:
error: forward declaration of 'struct itk::mallinfo'
gmake[2]: *** [Code/Common/CMakeFiles/ITKCommon.dir/itkMemoryUsageObserver.cxx.o]
Error 1

I have found out that mallinfo is deprecated on OpenBSD, instead they
use getrusage. mallinfo is being used in itkMemoryUsageObserver and
there is a comment in itkMemoryProbe.h to use getrusage. So I went
ahead and did some #ifdef for OpenBSD to use existing getrusage. I
will try to configure CDash to check if the tests passed sometime this
week. But in the meantime here's a full patch which is the output of
git diff in my local tree of ITK, which makes the compile go 100% in
OpenBSD though with compiler crashes. The ITK 3.20 source crashed much
more often compared to the head revision checked out from git. It is I
guess the growing pains when OpenBSD switched from gcc 3.3.5 to gcc
4.2.1 for i386/AMD64. I am running OpenBSD -current i386 as of
yesterday.

Thanks

diff --git a/Code/Common/itkMemoryUsageObserver.cxx
b/Code/Common/itkMemoryUsageObserver.cxx
index 87a68cb..7d7744e 100644
--- a/Code/Common/itkMemoryUsageObserver.cxx
+++ b/Code/Common/itkMemoryUsageObserver.cxx
@@ -42,11 +42,15 @@

 #if !defined( WIN32 ) && !defined( _WIN32 )
   #include <sys/resource.h>     // getrusage()
-  #if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined (
__sun__ ) && !defined( __FreeBSD__ )
+  #if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined (
__sun__ ) && !defined( __FreeBSD__ ) && !defined(__OpenBSD__)
     #include <malloc.h>           // mallinfo()
   #endif // !defined(__APPLE__) && !defined(__SUNPRO_CC) && !defined (__sun__)
 #endif // !defined(WIN32) && !defined(_WIN32)

+#if defined(__OpenBSD__)
+#include <stdlib.h>
+#endif
+
 namespace itk
 {
 MemoryUsageObserverBase::~MemoryUsageObserverBase()
@@ -384,7 +388,7 @@ SunSolarisMemoryUsageObserver::GetMemoryUsage()

 #endif //defined(__SUNPRO_CC) || defined (__sun__)

-#if !defined( WIN32 ) && !defined( _WIN32 )
+#if !defined( WIN32 ) && !defined( _WIN32 ) || defined(__OpenBSD__)

 /**         ----         SysResource Memory Usage Observer       ----       */

@@ -407,7 +411,7 @@ SysResourceMemoryUsageObserver::GetMemoryUsage()
   return 0;
 }

-#if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined (
__sun__ ) && !defined( __FreeBSD__ )
+#if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined (
__sun__ ) && !defined( __FreeBSD__ ) && !defined(__OpenBSD__)

 /**         ----         Mallinfo Memory Usage Observer       ----       */

@@ -426,7 +430,7 @@ MallinfoMemoryUsageObserver::GetMemoryUsage()
 }

 #endif //  !defined(__APPLE__) && !defined(__SUNPRO_CC) && !defined
(__sun__) &&
-       // !defined(__FreeBSD__)
+       // !defined(__FreeBSD__) && !defined(__OpenBSD__)

 #endif // Unix and Mac Platforms !defined(WIN32) && !defined(_WIN32)
 } //end namespace itk
diff --git a/Code/Common/itkMemoryUsageObserver.h
b/Code/Common/itkMemoryUsageObserver.h
index 8838019..014dd25 100644
--- a/Code/Common/itkMemoryUsageObserver.h
+++ b/Code/Common/itkMemoryUsageObserver.h
@@ -115,7 +115,7 @@ public:
   virtual ~SysResourceMemoryUsageObserver();
   virtual MemoryLoadType GetMemoryUsage();
 };
-#if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined (
__sun__ ) && !defined( __FreeBSD__ )
+#if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined (
__sun__ ) && !defined( __FreeBSD__ ) && !defined(__OpenBSD__)
 /** \class MallinfoMemoryUsageObserver
  * \brief The MallinfoMemoryUsageObserver
  */
@@ -145,7 +145,7 @@ class ITKCommon_EXPORT MemoryUsageObserver:
   public SunSolarisMemoryUsageObserver
 #elif defined( __APPLE__ ) && MAC_OS_X_VERSION >= MAC_OS_X_VERSION_10_2
   public MacOSXMemoryUsageObserver
-#elif defined( __APPLE__ ) || defined( __FreeBSD__ )
+#elif defined( __APPLE__ ) || defined( __FreeBSD__ ) || defined(__OpenBSD__)
   public SysResourceMemoryUsageObserver
 #else
   public MallinfoMemoryUsageObserver
diff --git a/Utilities/vxl/core/vnl/vnl_math.cxx
b/Utilities/vxl/core/vnl/vnl_math.cxx
index cc237e5..43e83fb 100644
--- a/Utilities/vxl/core/vnl/vnl_math.cxx
+++ b/Utilities/vxl/core/vnl/vnl_math.cxx
@@ -223,18 +223,18 @@ bool vnl_math_isfinite(long double x)

 #if defined(VCL_BORLAND)
 //: Return true if x is inf
-bool vnl_math_isinf(float x) { return !_finite(x) && !_isnan(x); }
+bool vnl_math_isinf(float x) { return !_finite(x) && !vnl_math_isnan(x); }
 //: Return true if x is inf
-bool vnl_math_isinf(double x) { return !_finite(x) && !_isnan(x); }
+bool vnl_math_isinf(double x) { return !_finite(x) && !vnl_math_isnan(x); }
 //: Return true if x is inf
-bool vnl_math_isinf(long double x) { return !_finitel(x) && !_isnanl(x); }
+bool vnl_math_isinf(long double x) { return !_finitel(x) &&
!vnl_math_isnan(x); }
 #elif !defined(VNL_HAS_NO_FINITE)
 //: Return true if x is inf
-bool vnl_math_isinf(float x) { return !finitef(x) && !isnan(x); }
+bool vnl_math_isinf(float x) { return !finitef(x) && !vnl_math_isnan(x); }
 //: Return true if x is inf
-bool vnl_math_isinf(double x) { return !finite(x) && !isnan(x); }
+bool vnl_math_isinf(double x) { return !finite(x) && !vnl_math_isnan(x); }
 //: Return true if x is inf
-bool vnl_math_isinf(long double x) { return !finitel(x) && !isnan(x); }
+bool vnl_math_isinf(long double x) { return !finitel(x) &&
!vnl_math_isnan(x); }
 #else
 // Assume IEEE floating point number representation
 bool vnl_math_isinf(float x)
{return(bMe(&x,0x7f800000L,sz_f)&&!bMp(&x,0x007fffffL,sz_f))||bMp(&x,0x7fffffffL,sz_f)==0x7f7fffffL;}
diff --git a/Utilities/vxl/core/vnl/vnl_matlab_header.h
b/Utilities/vxl/core/vnl/vnl_matlab_header.h
index 9e374ee..c4c13b6 100644
--- a/Utilities/vxl/core/vnl/vnl_matlab_header.h
+++ b/Utilities/vxl/core/vnl/vnl_matlab_header.h
@@ -40,7 +40,7 @@ namespace byteswap
 // byteswap routines, stolen from
 // ITK
 inline void
-swap32(void *ptr)
+swapIt32(void *ptr)
 {
   char one_byte;
   char *p = reinterpret_cast<char *>(ptr);
@@ -54,7 +54,7 @@ swap32(void *ptr)
   p[2] = one_byte;
 }
 inline void
-swap64(void *ptr)
+swapIt64(void *ptr)
 {
   char one_byte;
   char *p = reinterpret_cast<char *>(ptr);
diff --git a/Utilities/vxl/core/vnl/vnl_matlab_read.cxx
b/Utilities/vxl/core/vnl/vnl_matlab_read.cxx
index aca69d0..4cfdf36 100644
--- a/Utilities/vxl/core/vnl/vnl_matlab_read.cxx
+++ b/Utilities/vxl/core/vnl/vnl_matlab_read.cxx
@@ -129,11 +129,11 @@ void vnl_matlab_readhdr::read_hdr()
     }
   if(need_swap)
     {
-    byteswap::swap32(&hdr.type);
-    byteswap::swap32(&hdr.rows);
-    byteswap::swap32(&hdr.cols);
-    byteswap::swap32(&hdr.imag);
-    byteswap::swap32(&hdr.namlen);
+    byteswap::swapIt32(&hdr.type);
+    byteswap::swapIt32(&hdr.rows);
+    byteswap::swapIt32(&hdr.cols);
+    byteswap::swapIt32(&hdr.imag);
+    byteswap::swapIt32(&hdr.namlen);
     }
   if (varname)
     delete [] varname;
@@ -181,7 +181,7 @@ bool vnl_matlab_readhdr::read_data(T &v) { \
   vnl_matlab_read_data(s, &v, 1); \
   if(need_swap)                                   \
     {                                                   \
-    if(sizeof(v) == 4) byteswap::swap32(&v); else byteswap::swap64(&v);     \
+    if(sizeof(v) == 4) byteswap::swapIt32(&v); else
byteswap::swapIt64(&v);     \
     }                                                   \
   data_read = true; return *this; \
 } \
@@ -193,7 +193,7 @@ bool vnl_matlab_readhdr::read_data(T *p) { \
     {                                        \
     for(unsigned i = 0; i < rows()*cols(); i++) \
       {                                         \
-      if(sizeof(*p) == 4) byteswap::swap32(&(p[i])); else
byteswap::swap64(&(p[i]));        \
+      if(sizeof(*p) == 4) byteswap::swapIt32(&(p[i])); else
byteswap::swapIt64(&(p[i]));        \
       } \
     }                                        \
   data_read = true; return *this; \
@@ -207,7 +207,7 @@ bool vnl_matlab_readhdr::read_data(T * const *m) { \
     {                                                                   \
     for(unsigned i = 0; i < rows()*cols(); i++)                         \
       {                                                                 \
-      if(sizeof(T) == 4) byteswap::swap32(&(tmp[i])); else
byteswap::swap64(&(tmp[i]));     \
+      if(sizeof(T) == 4) byteswap::swapIt32(&(tmp[i])); else
byteswap::swapIt64(&(tmp[i]));     \
       } \
     } \
   int a, b; \

On Sat, Aug 28, 2010 at 11:13 PM, Amit Kulkarni <amitkulz at gmail.com> wrote:
> Hi,
> I switched to FreeBSD 8.1 and the thing compiled fine. Sorry to be a bother.
> It has the same gcc version. So its OpenBSD specific thing which was
> stopping compilation.
> Thanks


More information about the Insight-users mailing list