3

This question suggests that the best way to triangulate a polygon with holes is to use Shewchuk's Triangle library, but I'm having trouble getting it to compile on my mac OSX. It is a very popular program that has been around for a while, and therefore should be relatively easy to compile, I'm just inexperienced with C.

This is the error I'm getting:

$ make
cc -O -DLINUX -I/usr/X11R6/include -L/usr/X11R6/lib -o ./triangle ./triangle.c -lm
Undefined symbols:
  "__FPU_SETCW", referenced from:
   _exactinit in ccrEJvxc.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [triangle] Error 1

I'm trying to comment out certain flags (i.e. #define LINUX, etc.) but I get a different set of errors for each combination.

Could someone walk me through step-by-step how to compile (and possibly call) this program on a mac?

Community
  • 1
  • 1
dsg
  • 12,924
  • 21
  • 67
  • 111
  • As I recall, triangle's exact arithmetic algorithms require very particular treatment of the floating point control word. The `__FPU_SETCW` symbol suggests the use of the 8087 FPU. I believe that the code is relatively plain C code (it's not C++ by the way) and I'd be surprised if this wasn't your only block. I recommend you consult the Mac C compiler documentation to find out the means to control FP operations (rounding control, underflow control, exception masks etc.) – David Heffernan Jan 22 '11 at 09:03
  • I think you'll find the options you need in `xmmintrin.h`. You'll need to map across from 8087 setcw to SSE equivalents. Apparently you can disable SSE and force the use of 8087 on the Mac but it doesn't sound like the right approach to me. – David Heffernan Jan 22 '11 at 09:33
  • I'm looking in the `xmmintrin.h`, but it does not contain `__FPU_SETCW` or any mention of `FPU` at all. Are you saying I have to add some lines? – dsg Jan 22 '11 at 09:52
  • No it doesn't contain FPU_SETCW. You first need to understand 8087 control word settings and then map that across to the equivalent in SSE, as exposed in xmmintrin.h. – David Heffernan Jan 22 '11 at 12:31

2 Answers2

4

I managed to compile on OS X by removing the -DLINUX flag from the definition of CSWITCHES in the makefile, as fpu_control.h seems to be linux specific.

Patrick Sanan
  • 2,375
  • 1
  • 23
  • 25
0

I don't believe that's a standard function and in any case I believe the Mac .. whose use of the Intel architecture post-dates SSE .. never had a reason to support 387-style FPU ops.

So your code is Linux-specific. You can either remove the linux specific code or implement do-nothing versions of its entry points.

I wouldn't do this myself, but you might get away with:

$ cat > /usr/include/fpu_control.h

#define _FPU_SETCW(cw) // nothing
#define _FPU_GETCW(cw) // nothing

Don't worry about the null implementations. You don't need to tweak the FPU exception and rounding modes.

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329