0

I'm interested if anyone has managed to port HCRF2 to Mac OS X. I get stuck when building a cpp file using malloc.h. Apparently this is a deprecated package and there's not a whole lot out there telling you how to port programs using it. Any help would be greatly appreciated as I am not a C++ man.

[  2%] Building CXX object hCRF/CMakeFiles/hCRF.dir/src/matrixSSE2.cpp.o
/Volumes/LocalScratchHD/LocalHome/savkov/Software/HCRF2.0b/libs/shared/hCRF/src/matrixSSE2.cpp:9:10: error: 'malloc.h' file not found with <angled> include; use "quotes" instead
#include <malloc.h>
     ^~~~~~~~~~
     "malloc.h"
/Volumes/LocalScratchHD/LocalHome/savkov/Software/HCRF2.0b/libs/shared/hCRF/src/matrixSSE2.cpp:89:20: error: use of undeclared identifier 'memalign'
            pData = (double*)memalign(16, size*sizeof(double));
                             ^
2 errors generated.
make[2]: *** [hCRF/CMakeFiles/hCRF.dir/src/matrixSSE2.cpp.o] Error 1
make[1]: *** [hCRF/CMakeFiles/hCRF.dir/all] Error 2
make: *** [all] Error 2

UPDATE:

I copied malloc.h into the source folder and things went a bit further. Now I get another error:

/.../HCRF2.0b/libs/shared/hCRF/src/matrixSSE2.cpp: In member function 'void Matrix<elType>::create(int, int, elType) [with elType = double]':
/.../HCRF2.0b/libs/shared/hCRF/src/matrixSSE2.cpp:89:52: error: 'memalign' was not declared in this scope
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
Aleksandar Savkov
  • 2,894
  • 3
  • 24
  • 30

1 Answers1

4

OSX lacks memalign(), but it does have posix_memalign(). It has a different signature than memalign(), so you'll have to tweak the sources a bit. Where you have:

pData = (double*)memalign(16, size*sizeof(double));

you can re-write that as (untested):

err = posix_memalign((void **)&pData, 16, size*sizeof(double));

But I believe that OSX always allocates on 16 byte boundaries. If this is the case, you can just as easily use malloc():

pData = (double *)malloc(size*sizeof(double));

(If you go this route, it would be wise to include an assertion that verifies pData to be on a 16 byte boundary.)

fearless_fool
  • 33,645
  • 23
  • 135
  • 217