Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

341
Views
Attempting to use execvpe(...) but get implicit declaration error - even though I think I'm using the correct argument types

I am getting the following warning when I compile:

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

^

My understanding is that this occurs when the function you are trying to use has the incorrect types of arguments. However, I am pretty sure that I am supplying the correct arguments to:

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

as described in the Linux man 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;

}

Anyone know why I keep getting this error? Thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

"implicit declaration of function" means the compiler has not seen a declaration for that function. Most compilers, including gcc, will assume that the way the function has been used is correct and the return type is an int. This is generally a bad idea. Even if you use the arguments correctly it will still throw this error as the compiler does not know you are using the arguments correctly. The declaration of execvpe is only included if _GNU_SOURCE is defined before including unistd.h as it is a GNU extension.

You will want something like:

#define _GNU_SOURCE
#include <unistd.h>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!