[英]g++ comes up with errors when run with execlp, but not from the terminal?
Using fork() and execlp(), I'm trying to compile a cpp file to a .so. 我正在尝试使用fork()和execlp()将cpp文件编译为.so。 I'm running a copied g++-4.8 executable that's in my project's directory tree. 我正在运行一个复制的g ++-4.8可执行文件,该文件位于项目的目录树中。 When run from the terminal, everything goes smoothly and I end up with a working dynamic library, but when I make a child process and use execlp to do the same thing, I get an error: 从终端运行时,一切运行顺利,最终得到了一个可以使用的动态库,但是当我创建一个子进程并使用execlp做同样的事情时,出现错误:
g++-4.8: error: @@@: No such file or directory
This is repeated 6 times with a few characters in the "filename" changed around a bit. 重复6次,“文件名”中的几个字符略有变化。 To compare, this is what I write in the terminal: 作为比较,这是我在终端中写的内容:
$ g++/bin/g++-4.8 -fPIC -shared bob.cpp -o bob.so
...and this is the code that generates the error: ...这是生成错误的代码:
if (fork() == 0) {
execlp("g++/bin/g++-4.8", "g++/bin/g++-4.8", "-fPIC", "-shared", "bob.cpp", "-o", "-bob.so");
}
bob.cpp is in the working directory of the parent process, and the terminal code is executed from that same directory. bob.cpp在父进程的工作目录中,并且从该目录执行终端代码。
@@@
is a typical sequence from the header of a binary (ELF) file. @@@
是二进制(ELF)文件头中的典型序列。 You forgot to NULL
terminate your argument list to execlp()
, so it read garbage and tried to pass it to g++. 您忘记了使用NULL
将您的参数列表终止到execlp()
,因此它读取垃圾并将其传递给g ++。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.