Home > Back-end >  Naming conflict between c library and c library
Naming conflict between c library and c library

Time:09-30

I do not normally program in C and I am more comfortable in C. I have a C library that I wrote and now I am trying to use it together with a specific function (a graph planarity testing function) in the Boost C Graph library. In so doing, I am getting a compilation error which seems to involve a naming conflict between my part of my own c libraries linked list implementation and some far away link function in some directory in the bowls of my computer that is being called on by one of these Boost library functions:

    ./list.c:7:22: error: redefinition of 'link' as different kind of symbol
typedef struct node *link;
                     ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:464:6: note: previous definition is here
int      link(const char *, const char *);
         ^
In file included from boost_graph_test.cpp:15:
In file included from ./graph_dt.c:1:

How should I go about fixing this naming conflict (I would rather not change the code in my existing c library)? I feel like some namespace thing should do the trick but unfortunately, I am not sure what exactly to do.

CodePudding user response:

The link function is a standard system function used for creating hard links and symbolic links in the filesystem. It's declared in unistd.h (which is used pretty commonly) and has been around since 4.3 BSD. So you can't use this name for something else.

This means that, given this this is a C library, you'll have to rename your variable.

  • Related