3

Suppose I have such code:

lib.h:

void func();

lib.cpp:

void __attribute__((weak)) func()
{
    printf("original");
}

and these code would be compile into libA.a.

clang++ lib.cpp -o libA.a

Then in my test unit I want to override this func function such as:

test.cpp:

#include "lib.h"
void func()
{
    printf("override");
}

And:

clang++ test.cpp -lA

But in my result the output is always original.

What is the right way to weak a static lib function and then override it externally?

jayatubi
  • 1,972
  • 1
  • 21
  • 51
  • Looks like a dupe of either http://stackoverflow.com/questions/23079997/override-weak-symbols-in-static-library and/or http://stackoverflow.com/questions/13089166/how-to-make-gcc-link-strong-symbol-in-static-library-to-overwrite-weak-symbol – Michael Anderson Jul 13 '15 at 03:49

0 Answers0