I guess you have a cyclic symbol dependency the compiler can't handle. The reason you're just getting an undefined constant afterwards would then be that the compiler has deployed a placeholder object in an attempt to deal with the situation, and indexing such an object resulted in UNDEFINED (which the compiler hoped to correct in the second pass, but failed). That should at least be caught so a compiler error is reported instead, but, well, the resolver is basically broken by design and it has proved very difficult to fix.
You could try to compile your module with -DCOMPILER_DEBUG. Then you'll see the order your files get compiled, which might give you a hint.
(using #if constant(someconstant) directly doesnt work in the first place)
The recursive resolver problems aside, #if constant(.someconstant) might be a better alternative.