www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - undefined reference to `execvpe'

reply Ameer Armaly <ameer charter.net> writes:
Hi all.
I'm trying to use the execv  function in std.process, but when the program 
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
Aug 19 2004
parent reply kinghajj <kinghajj_member pathlink.com> writes:
In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...
Hi all.
I'm trying to use the execv  function in std.process, but when the program 
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Aug 19 2004
next sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
kinghajj wrote:
 In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...
 
Hi all.
I'm trying to use the execv  function in std.process, but when the program 
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. This // implementation provides what is missing. /* execvpe() - execve() with PATH search */ import std.c.process; import std.c.stdlib; import std.string; extern (C) int execvpe(char *file_arg, char **argv, char **envp) { int ret; char[] file = file_arg[0..strlen(file_arg)]; char[] path; char[] next; char *temp = getenv("PATH"); path = temp[0..strlen(temp)]; while(path.length > 0) { temp = strchr(path, ':'); if(temp == null) next.length = 0; else { next = path[temp-cast(char*)path+1..length]; path = path[0..temp-cast(char*)path]; } // If the exectuable is found, then this never returns. // But if the executable is not found, then this returns // some nonzero value. ret = execve(path~"/"~file, argv, envp); path = next; } return ret; }
Aug 20 2004
parent reply "Matthew" <admin.hat stlsoft.dot.org> writes:
Russ, I'll take this as a basis for a permanent fix, if that's ok with you?
(I've some ideas for making it a bit neater,
and we would only implement the D version, but essentially it's a sound idea.)

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg4udj$b0j$1 digitaldaemon.com...
 kinghajj wrote:
 In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...

Hi all.
I'm trying to use the execv  function in std.process, but when the program
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. This // implementation provides what is missing. /* execvpe() - execve() with PATH search */ import std.c.process; import std.c.stdlib; import std.string; extern (C) int execvpe(char *file_arg, char **argv, char **envp) { int ret; char[] file = file_arg[0..strlen(file_arg)]; char[] path; char[] next; char *temp = getenv("PATH"); path = temp[0..strlen(temp)]; while(path.length > 0) { temp = strchr(path, ':'); if(temp == null) next.length = 0; else { next = path[temp-cast(char*)path+1..length]; path = path[0..temp-cast(char*)path]; } // If the exectuable is found, then this never returns. // But if the executable is not found, then this returns // some nonzero value. ret = execve(path~"/"~file, argv, envp); path = next; } return ret; }
Aug 20 2004
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I don't mind, but I can't guarantee it isn't buggy.  In particular, I 
think that I should have added    ~\0    on the execve() call.  Right?

Matthew wrote:
 Russ, I'll take this as a basis for a permanent fix, if that's ok with you?
(I've some ideas for making it a bit neater,
 and we would only implement the D version, but essentially it's a sound idea.)
 
 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg4udj$b0j$1 digitaldaemon.com...
 
kinghajj wrote:

In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...


Hi all.
I'm trying to use the execv  function in std.process, but when the program
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. This // implementation provides what is missing. /* execvpe() - execve() with PATH search */ import std.c.process; import std.c.stdlib; import std.string; extern (C) int execvpe(char *file_arg, char **argv, char **envp) { int ret; char[] file = file_arg[0..strlen(file_arg)]; char[] path; char[] next; char *temp = getenv("PATH"); path = temp[0..strlen(temp)]; while(path.length > 0) { temp = strchr(path, ':'); if(temp == null) next.length = 0; else { next = path[temp-cast(char*)path+1..length]; path = path[0..temp-cast(char*)path]; } // If the exectuable is found, then this never returns. // But if the executable is not found, then this returns // some nonzero value. ret = execve(path~"/"~file, argv, envp); path = next; } return ret; }
Aug 20 2004
next sibling parent reply "Matthew" <admin.hat stlsoft.dot.org> writes:
No worries, mate. I just meant I'd steal the idea. I'm a pathological rewriter.
;)

Are you, or is anyone else, up for testing this on Linux? (I'm yet to set up D
on my linux box, and I am woefully short
on time. Of course, this probably means I shouldn't write any more
multi-platform code before I do ...<G>)

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg62sj$uof$1 digitaldaemon.com...
 I don't mind, but I can't guarantee it isn't buggy.  In particular, I
 think that I should have added    ~\0    on the execve() call.  Right?

 Matthew wrote:
 Russ, I'll take this as a basis for a permanent fix, if that's ok with you?
(I've some ideas for making it a bit
neater,
 and we would only implement the D version, but essentially it's a sound idea.)

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg4udj$b0j$1 digitaldaemon.com...

kinghajj wrote:

In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...


Hi all.
I'm trying to use the execv  function in std.process, but when the program
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. This // implementation provides what is missing. /* execvpe() - execve() with PATH search */ import std.c.process; import std.c.stdlib; import std.string; extern (C) int execvpe(char *file_arg, char **argv, char **envp) { int ret; char[] file = file_arg[0..strlen(file_arg)]; char[] path; char[] next; char *temp = getenv("PATH"); path = temp[0..strlen(temp)]; while(path.length > 0) { temp = strchr(path, ':'); if(temp == null) next.length = 0; else { next = path[temp-cast(char*)path+1..length]; path = path[0..temp-cast(char*)path]; } // If the exectuable is found, then this never returns. // But if the executable is not found, then this returns // some nonzero value. ret = execve(path~"/"~file, argv, envp); path = next; } return ret; }
Aug 20 2004
parent reply Jonathan Leffler <jleffler earthlink.net> writes:
Matthew wrote:

 No worries, mate. I just meant I'd steal the idea. I'm a pathological
rewriter. ;)
 
 Are you, or is anyone else, up for testing this on Linux? (I'm yet 
 to set up D on my linux box, and I am woefully short on time. Of
 course, this probably means I shouldn't write any more 
 multi-platform code before I do ...<G>)

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg62sj$uof$1 digitaldaemon.com...
 
I don't mind, but I can't guarantee it isn't buggy.  In particular, I
think that I should have added    ~\0    on the execve() call.  Right?

Matthew wrote:

 Russ, I'll take this as a basis for a permanent fix, if that's
 ok  with you? (I've some ideas for making it a bit
 neater, and we would only implement the D version, but
 essentially it's a  sound idea.)

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote:
kinghajj wrote:
In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...
 I'm trying to use the execv function in std.process, but 
 when the program links, it gives me an undefined
 reference to `execvpe' message. This is using the latest
 dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. // This implementation provides what is missing. /* execvpe() - execve() with PATH search */
Wouldn't it be easier to do it as 'execvp() setting the environment'? In C (sorry, I'm still more fluent in that): extern char **environ; int execvp(char *file_arg, char **argv, char **envp) { char **old_env = environ; environ = envp; execvp(file_arg, argv); // Oops - must have failed! environ = old_env; return(-1); } FYI: environ is the one variable defined by POSIX with no standard header. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler earthlink.net, jleffler us.ibm.com Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
Aug 20 2004
parent "Matthew" <admin.hat stlsoft.dot.org> writes:
"Jonathan Leffler" <jleffler earthlink.net> wrote in message
news:cg6e21$146m$1 digitaldaemon.com...
 Matthew wrote:

 No worries, mate. I just meant I'd steal the idea. I'm a pathological
rewriter. ;)

 Are you, or is anyone else, up for testing this on Linux? (I'm yet
 to set up D on my linux box, and I am woefully short on time. Of
 course, this probably means I shouldn't write any more
 multi-platform code before I do ...<G>)

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg62sj$uof$1 digitaldaemon.com...

I don't mind, but I can't guarantee it isn't buggy.  In particular, I
think that I should have added    ~\0    on the execve() call.  Right?

Matthew wrote:

 Russ, I'll take this as a basis for a permanent fix, if that's
 ok  with you? (I've some ideas for making it a bit
 neater, and we would only implement the D version, but
 essentially it's a  sound idea.)

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote:
kinghajj wrote:
In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...
 I'm trying to use the execv function in std.process, but
 when the program links, it gives me an undefined
 reference to `execvpe' message. This is using the latest
 dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. // This implementation provides what is missing. /* execvpe() - execve() with PATH search */
Wouldn't it be easier to do it as 'execvp() setting the environment'? In C (sorry, I'm still more fluent in that): extern char **environ; int execvp(char *file_arg, char **argv, char **envp) { char **old_env = environ; environ = envp; execvp(file_arg, argv); // Oops - must have failed! environ = old_env; return(-1); } FYI: environ is the one variable defined by POSIX with no standard header.
Indeed. But I don't think D supports that. (Of course, I could have provided execvpe() in C, but that'd have been more hassle.) Nonetheless, it's worth keeping mind. Thanks
Aug 20 2004
prev sibling parent "Matthew" <admin.hat stlsoft.dot.org> writes:
I'm posting the link to an alpha on the bugs ng shortly. If you can do a test,
and report back to the bugs ng, that'd be
great!

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg62sj$uof$1 digitaldaemon.com...
 I don't mind, but I can't guarantee it isn't buggy.  In particular, I
 think that I should have added    ~\0    on the execve() call.  Right?

 Matthew wrote:
 Russ, I'll take this as a basis for a permanent fix, if that's ok with you?
(I've some ideas for making it a bit
neater,
 and we would only implement the D version, but essentially it's a sound idea.)

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:cg4udj$b0j$1 digitaldaemon.com...

kinghajj wrote:

In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...


Hi all.
I'm trying to use the execv  function in std.process, but when the program
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Phobos uses execvpe(), but it isn't implemented by glibc, at least on my system. execvpe() is just like execve(), except that it searches through your $PATH to find the executable. So I added this function to my program, which seemed to make it work. Feel free to fix the code if you find any bugs: // HACK HACK HACK // phobos uses execvpe(), which is not implemented in glibc. This // implementation provides what is missing. /* execvpe() - execve() with PATH search */ import std.c.process; import std.c.stdlib; import std.string; extern (C) int execvpe(char *file_arg, char **argv, char **envp) { int ret; char[] file = file_arg[0..strlen(file_arg)]; char[] path; char[] next; char *temp = getenv("PATH"); path = temp[0..strlen(temp)]; while(path.length > 0) { temp = strchr(path, ':'); if(temp == null) next.length = 0; else { next = path[temp-cast(char*)path+1..length]; path = path[0..temp-cast(char*)path]; } // If the exectuable is found, then this never returns. // But if the executable is not found, then this returns // some nonzero value. ret = execve(path~"/"~file, argv, envp); path = next; } return ret; }
Aug 20 2004
prev sibling parent "Matthew" <admin.hat stlsoft.dot.org> writes:
It's my fault. I didn't do the due diligence for ensuring that the APIs were
available on Linux.

It's been noted, and is on the list for a fix. (Which might be to remove it!)

Alternatively, we might do a custom search, as has been suggested by Russ. (I'm
just looking at that now.)

"kinghajj" <kinghajj_member pathlink.com> wrote in message
news:cg358e$2hh6$1 digitaldaemon.com...
 In article <Pine.LNX.4.61.0408191703500.3453 debian>, Ameer Armaly says...
Hi all.
I'm trying to use the execv  function in std.process, but when the program
links, it gives me an  undefined reference to `execvpe' message.
This is using the latest dmd on a linux system.
I get that too. I don't know why: the prototype for execvpe is in std.c.process (which std.process imports)... I even tried re-compiling the library, but it still failed.
Aug 20 2004