## Eigen Gotcha: sizeof Eigen::Index depends on system

Part of the magic behind libigl’s header-only / static-library duality is making use of explicit template instantiations. Usually I can just literally copy the compiler “missing symbol” error lines, stick template in front of them and a semicolon ; at the end to add a symbol to the static library.

Unfortunately this falls apart for any templates that are defined via Eigen::Index (e.g., via Eigen::MatrixXi::Index).

My compiler (clang on Mac OS X) translates these to long in the output lines. And on Mac OSX with clang a long is 64 bits long.

Unfortunately, long is only 32 bits long on Windows and there Eigen::Index is translated to __int64 (which has 64 bits). So then I still get a missing symbol.

This is probably more of a clang compiler gotcha. I’m not sure Eigen could do anything to help me here.

Update: I take that back. Eigen could define EIGEN_DEFAULT_DENSE_INDEX_TYPE to a fixed size value (e.g., int64_t) rather than the system dependent std::ptrdiff_t, but there’s an obvious advantage to using the best type on this system rather than a fixed size that might be too big (or too small).

Tags: , ,