Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call function in a static library without implementation

I'd like to know if it's possible, within a static library, call a function that the implementation is in my application instead of in the library.

Like this:

Static Library

foo.h

void foo_func();

foo.c

#include "foo.h"

void foo_func()
{
    app_func();
}

Application

main.c

#include <foo.h>

uint8_t flag = FALSE;

uint8 main()
{
    foo_func();

    while(!flag);

    return 0;
}

void app_func()
{
     flag = TRUE;
}
like image 561
Gustavo Salomão Avatar asked Mar 16 '26 12:03

Gustavo Salomão


1 Answers

A static library created with ar is just an archive of .o object files. You can call any external functions in static library created with ar, present or not, like with any .o file. While it is possible, calling back the application is may be not the best design choice.

like image 57
ouah Avatar answered Mar 18 '26 01:03

ouah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!