-1
execl("/usr/bin/cc","cc","myprog.c",NULL)

I use the this line for compiler to myprog.c in myMainProg. But myprog.c have #include "math.h" . So I have to add -lm. How can I do that?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
o_O
  • 51
  • 7

1 Answers1

1

Command (from shell) to link your program should be:

cc myprog.c -o myprog -lm

So if you want to use execl to compile it from another program you should use:

execl("/usr/bin/cc","cc","myprog.c", "-o", "myprog", "-lm", (char *) NULL);

Edit: I almost forgot when using execl() the ending NULL argument must be cast to char *

jdarthenay
  • 3,062
  • 1
  • 15
  • 20