Trying to use execvpe (...) but getting an implicit declaration error - although I think I am using the correct argument types

I get the following warning when compiling:

execute.c:20:2: warning: implicit declaration of function ‘execvpe’[-Wimplicit-function-declaration] execvpe("ls", args, envp);

      

^

I understand this happens when the function you are trying to use has the wrong argument types. However, I'm pretty sure I'll put the correct arguments:

int execvpe(const char *file, char *const argv[], char *const envp[]);

      

as described in Linux Personal Page

Here are the relevant parts of my code:

#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>

void test_execvpe(char* envp[])
{
    const char* temp = getenv("PATH");
    char path[strlen(temp)+1];
    strcpy(path, temp);
    printf("envp[%d] = %s\n", 23, envp[23]); //print PATH
    char* args[] = {"-l", "/usr", (char*) NULL};
    execvpe("ls", args, envp);
}

int main( int argc, char* argv[], char* envp[])
{

    //test_execlp();
    test_execvpe(envp);
    return 0;

}

      

Does anyone know why I keep getting this error? Thank!

+3


source to share


1 answer


"implicit function declaration" means that the compiler has not seen a declaration for that function. Most compilers, including gcc, will assume that the way the function is used is correct and the return type is int

. This is usually a bad idea. Even if you use the arguments correctly, it will still throw this error, since the compiler doesn't know that you are using the arguments correctly. The declaration execvpe

is only included if _GNU_SOURCE

defined before unistd.h was included, as it is a GNU extension.

You need something like:



#define _GNU_SOURCE
#include <unistd.h>

      

+5


source







All Articles