0

I'm trying to compile OpenCascade (OCE) with g++/gcc on Alpine Linux. It builds fine on Ubuntu but the same project fails on Apline with the errors:

OSD_MemInfo.cxx: In member function 'void OSD_MemInfo::Update()':
OSD_MemInfo.cxx:146:19: error: variable 'OSD_MemInfo::Update()::mallinfo aMI' has initializer but incomplete type
   struct mallinfo aMI = mallinfo();
                   ^~~
OSD_MemInfo.cxx:146:34: error: invalid use of incomplete type 'struct OSD_MemInfo::Update()::mallinfo'
   struct mallinfo aMI = mallinfo();
                                  ^
OSD_MemInfo.cxx:146:10: note: forward declaration of 'struct OSD_MemInfo::Update()::mallinfo'
   struct mallinfo aMI = mallinfo();
          ^~~~~~~~

I can't really understand why this is an error for Alpine while not Ubuntu, does anyone have any ideas why or has had similar issues?

JacobP
  • 561
  • 3
  • 21
  • 1
    This looks similar to https://askubuntu.com/questions/1143889/why-18-04-malloc-h-does-not-have-mallinfo. Looks like the compiler is unable to find the definition of struct mallinfo which should be defined in malloc.h. See http://man7.org/linux/man-pages/man3/mallinfo.3.html – Yasir Khan Oct 25 '19 at 08:07
  • Thanks for looking in to this. Very strange if the compiler can't find malloc as other things also compile fine on Alpine. – JacobP Oct 25 '19 at 13:25

2 Answers2

2

For reference, this is an issue of musl libc not including the mallinfo functionality as it is a GNU glibc addition. To make OpenCascade build on such as system one can comment lines 146-147 in src/OSD/OSD_MemInfo.cxx (for OCE 0.18.3).

// struct mallinfo aMI = mallinfo();
// myCounters[MemHeapUsage] = aMI.uordblks;

This leads to simply ignoring the memory heap usage which seems to be safe, as it is only used for information and statistics.

However, one also has to comment three lines (221-222, 342-343, 398) in src/OSD/OSD_signal.cxx which call feenableexcept (also only defined in glibc)

// if (fFltExceptions)   
//   feenableexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);

After this OpenCascade should build on Alpine linux.

JacobP
  • 561
  • 3
  • 21
  • Also, in recent versions, `libexecinfo` is needed on `musl` to build (it's a BSD library which implements the `execinfo` extension for libc implementations which do not support it). – Enderger Sep 27 '22 at 17:58
0

To build on JacobP and Enderger's remarks (update for alpine>=3.17):

  • All references to mallinfo should be commented out (not available in glibc on musl/alpine)
  • All references to feenableexcept, fedisableexcept and fegetexcept should be commented out (also not available in glibc on musl/alpine)
  • libexecinfo is not available anymore on alpine>=3.17, and therefore all references to its functions backtrace and backtrace_symbols should be commented out as well.

You can find a Dockerfile here: https://github.com/JohannesVerherstraeten/docker-opencascade