How to check if a function exists in C/C++?

Using GCC you can:

void func(int argc, char *argv[]) __attribute__((weak)); // weak declaration must always be present

// optional definition:
/*void func(int argc, char *argv[]) { 
    printf("FOUND THE FUNCTION\n");
    for(int aa = 0; aa < argc; aa++){
        printf("arg %d = %s \n", aa, argv[aa]);

int main(int argc, char *argv[]) {
    if (func){ 
        func(argc, argv); 
    } else {
        printf("did not find the function\n");

If you uncomment func it will run it otherwise it will print “did not find the function\n”.

Leave a Comment