Reputation: 191
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.
Upvotes: 1
Views: 210
Reputation: 12668
Well:
typedef struct node *link;
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:464:6: note: previous definition is here
link
as a type.int link(const char *, const char *);
^
In file included from boost_graph_test.cpp:15:
In file included from ./graph_dt.c:1:
link
to make a second link of a file.You cannot have a type and a function with the same name. The solution IMHO is to rename your type to something like
typedef struct node *link_t;
and Voila!!!
(Note: you will have to search for all occurences of type link
in your sources and rename them also to link_t
)
Upvotes: 1
Reputation: 223972
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.
Upvotes: 3