0

When we work on Turbo C, we get all the functions and header files by default which we can include normally by #inlcude eg: stdlib.h, math.h

But when writing a simple program using such header files I am getting error because I'm unable to include these files. Aren't these header files available by default for us to use? If yes then how to use such header files? When I used a function sqrt in "math.h" I was getting error as math.h was not getting included so I had to include it in the following command:

cc -c aaa.c -I/usr/local/ssl/include
gcc -o aaa aaa.c -I/usr/local/ssl/include -L/usr/local/ssl/lib -lcrypto -lm
./aaa

In this command the 2nd one is having -lm at the end to include math.h

again similarly I used a function itoa() which is in stdlib.h which I am executing on a UNIX Solaris server, but it is not getting included and I am gettig error. Now I don't know how to add this header file.

mawia
  • 9,169
  • 14
  • 48
  • 57
maddy2012
  • 153
  • 1
  • 3
  • 15

3 Answers3

3

The math.h header is included normally. The code can compile. However, the compiler won't find the compiled binary (the implementation of math.h) to link to unless you specify it to do so. So you have to specify -lm in the command.

itoa() is not a standard function in stdlib.h, so do not use it. You can use sprintf instead.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
  • I want to get the ascii code of every individual character in a string like this "AB12" in hex like this "41 42 31 32". Will sprintf serve my purpose? And I also checked in the turbo c documentation. itoa() is there in the stdlib.h – maddy2012 May 23 '12 at 07:59
  • It may be in stdlib.h of Turbo C, but it is not in the standard of stdlib.h. Support for itoa may or may not be available cross-platform, so it is safer to use whatever is standard. If you want to convert from string to long, you have strtol. If you want to convert from int/long to string, use printf or sprintf (depending on your purpose). – nhahtdh May 23 '12 at 08:03
  • How does one find out what is the name of the file to link to? Like I linked the math.h's implementation file by -lm I have to include another header file which is in crypto library of openssl. I want to know if I have a header file what would be the name of its implementation file and how to link it? – maddy2012 May 23 '12 at 11:50
  • I think you can find the answer in this question: http://stackoverflow.com/questions/8829670/openssl-link-options-lssl-and-lcrypto-in-gcc – nhahtdh May 24 '12 at 03:52
0

your compiler should provide command line settings where you can specify include directories, library directories etc. it is best if you take a look at your compiler documentation.

E.g. visual studio has a command switch -I to specify include folders

alt. in some cases it can be specified as an environment variable e.g. set INCLUDE=...

it all depends on what compiler you use.

AndersK
  • 35,813
  • 6
  • 60
  • 86
0

By default these are standard library functions that are exported from libc and they should be available in any Unix/Linux flavor. You can check where the header file exists using command like

find / -name "stdio.h" 2>/dev/null

Also make sure you link to libc using -l libc

Also, which compiler are you using? I suggest you use gcc, that way the include config is already done for the compiler, you can use it as is and get going.

PavanMysore
  • 189
  • 3
  • 12