Linking problem (undefined reference)

Hi my friends.
I hope somebody can help me.
I have included in my project (written in C++11) some files from a another author, which are written in C. I use Qt, so i have included next files in my project (Swaps.pro) there :
traces.c
schreier.c
...
A function which is called "Traces" are defined inside "traces.c" :
<code>
Traces(sparsegraph *g_arg, int *lab, int *ptn,
int *orbits_arg, TracesOptions *options_arg, TracesStats *stats_arg,
sparsegraph *canong_arg) {
//...
}
</code>
but, the linker still complains :
/home/daniel/programacion/Qt/Swaps/tracestest.cpp:-1: error: undefined reference to `Traces(sparsegraph*, int*, int*, int*, TracesOptions*, TracesStats*, sparsegraph*)'

Somebody have a idea what is happen ?
Thanks for any idea. Daniel
C doesn't mangle names, so if you try to declare a C function in a C++ source by just copy-pasting its signature, you'll generate a reference to a mangled symbol, which probably doesn't exist. extern "C" must be placed in front of the declaration:
 
extern "C" void foo();

When including C-only headers, this can be done:
1
2
3
extern "C"{
#include "foo.h"
}
My god !! Thanks you.
You have resolved my problem in one second !
I do this :
1
2
3
extern "C" {
#include "nauty26r5/traces.h"
}

and now there not left linking problems.
Thanks. Daniel
Topic archived. No new replies allowed.