0
#include <math.h> 

int main() {
    nan("");
}

The above code works on Linux with gcc fn.c -lm. It doesn't on solaris-sparc. How do I fix this?

The error message is:

Undefined symbol nan, first referenced in file /var/tmp//ccsdneUZ.o ld: fatal: Symbol referencing errors. No output written to test collect2: ld returned 1 exit status.
Kylos
  • 1,888
  • 14
  • 24
Dr.Evil
  • 19
  • 3
  • Not sure how particular C compilers generally are, but you have a function declared as returning an integer, and no return. Beyond that, what errors are you receiving? It's hard to diagnose a problem without any context. – Matthew Scharley Jan 19 '12 at 09:05
  • Undefined symbol nan, first referenced in file /var/tmp//ccsdneUZ.o ld: fatal: Symbol referencing errors. No output written to test collect2: ld returned 1 exit status. nan is not accessible through the man pages either on solaris-sparc – Dr.Evil Jan 19 '12 at 09:08
  • Compiles, links and runs for me using `gcc-4.3 (GCC) 4.3.3` on `5.10 Generic_118833-17 sun4u sparc SUNW,Sun-Fire-V440`. Not that it does anything useful. – johnsyweb Jan 19 '12 at 09:09
  • i am using a old version of gcc version 3.4.6 on 5.8 Generic_117350-02 – Dr.Evil Jan 19 '12 at 09:11
  • `nan()` isn't universally available. See this answer for more: http://stackoverflow.com/a/1923933/15537 – Matthew Scharley Jan 19 '12 at 09:17
  • 1
    possible duplicate of [How to use nan and inf in C?](http://stackoverflow.com/questions/1923837/how-to-use-nan-and-inf-in-c) – unwind Jan 19 '12 at 10:02
  • does `double nan(const char* tagp)` exist in your math.h? – Bort Jan 19 '12 at 10:32
  • sorry... it is in bits/mathcalls.h – Bort Jan 19 '12 at 10:38
  • ok, i think i resolved it by defining my nan using strtod. thank you. – Dr.Evil Jan 19 '12 at 11:29

0 Answers0