2

I found some discussion, the answer is using static, another answer is renaming the function

but, if I don't have source code, how can I rename the function?

I also tried the static, but not work, error: "warning #2135: Static 'func' is not referenced."

What is the correct solution?

main.c

#include <stdio.h>
#include "liba.h"
#include "libb.h"

int main(int argc, char *argv[])
{
    printf("Main\n");
    func();
    return 0;
}

liba.h

static void func(void);

liba.c

#include <stdio.h>
#include "liba.h"

static void func(void)
{
    printf("lib a\n");
}

libb.h

static void func(void);

libb.c

#include <stdio.h>
#include "libb.h"

static void func(void)
{
    printf("lib b\n");
}
CL So
  • 3,647
  • 10
  • 51
  • 95
  • 1
    You can't. C doesn't have namespaces, so the functions in both libs are going to conflict. – Marc B Mar 18 '14 at 04:39
  • 1
    i think this is the solution for you http://stackoverflow.com/questions/678254/c-function-conflict – Jayesh Bhoi Mar 18 '14 at 04:49
  • C doesn't show polymorphic behaviour, Why don't you put some letters of library name in your function name to make it distinct? – Arslan Ali Mar 18 '14 at 04:49

3 Answers3

1

In C header file function are global and cause conflict if are of same name. You need to change the name to avoid conflict.

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
1

It can be done, but not directly. You need to abstract away the offending duplicate function behind a wrapper. As described by the answer here (linked by Jayesh):

If you don't control either of them you can wrap one of them up. That is compile another (statically linked!) library that does nothing except re-export all the symbols of the original except the offending one, which is reached through a wrapper with an alternate name.

Community
  • 1
  • 1
Baldrick
  • 11,712
  • 2
  • 31
  • 35
0

You can't do it as far as I know. I am not saying it is not possible, but impractical as 'c' doesn't allow polymorphism and namespaces. And yes the link shared by Jayesh is informative have a look What should I do if two libraries provide a function with the same name generating a conflict?

Community
  • 1
  • 1
Deva
  • 48
  • 6