0

Thanks for the help. I've tried a couple of things and can't seem to get it to compile. Say you have two files, say, program1.c and program2.c and you want to compile them into a single executable called run and you need to include the math.h library. I'm using Ubuntu LTS. Thank you for reading my question.

court
  • 53
  • 10

2 Answers2

3

gcc program1.c program2.c -lm -o yourProgram is the command. You might want sudo if you don't have necessary permissions.

Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
  • 1
    Only something as brain-dead as Ubuntu could require root to compile code :-) But +1 since your command line is right. – paxdiablo Jan 29 '14 at 03:47
  • Got it! Thanks! I left off the -o. Thank you so much. -court – court Jan 29 '14 at 03:48
  • Is Ubuntu not good? What's a good version of Unix that's free to use? – court Jan 29 '14 at 03:49
  • Almost every other linux is free to use @court. Try others, debian and fedora are my favorites, but you can try many. See here: distrowatch.com – Aniket Inge Jan 29 '14 at 03:50
  • Thanks! I have to use a version of Unix (or linux obviously) for classes here at Clemson and I just chose Ubuntu because I had heard people talking about it. You guys are awesome. Thanks seriously. – court Jan 29 '14 at 03:55
1

math.h is a (standard) header file, not a library. A header file contains the declarations and prototypes necessary for using features of a library. A library contains the actual object code. To compile your program, try:

gcc program1.c program2.c -o myprog

It's also possible you might have to add -lm to link to the math library.

ooga
  • 15,423
  • 2
  • 20
  • 21