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?
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.