简体   繁体   English

如何使用 execl() 编译包含 math.h 库的程序

[英]How compiler a program which include math.h library with execl()

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

I use the this line for compiler to myprog.c in myMainProg.我在 myMainProg 中将这一行用于编译器到 myprog.c。 But myprog.c have #include "math.h" .但是 myprog.c 有 #include "math.h" 。 So I have to add -lm.所以我必须添加-lm。 How can I do that?我怎样才能做到这一点?

Command (from shell) to link your program should be:链接程序的命令(来自 shell)应该是:

cc myprog.c -o myprog -lm

So if you want to use execl to compile it from another program you should use:因此,如果您想使用execl从另一个程序编译它,您应该使用:

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 *编辑:我几乎忘记了在使用execl()时必须将结尾的NULL参数execl()char *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM