I believe both function prototypes (declarations) and function definitions need to have extern "C" around them if you want to use the code in C++. This means add ZuK's macros-plus-code to both the sources and the headers. Try it and see what happens.
There's a bit of confusion in this thread regarding compiling multiple files etc so I'll try to clear that up. If you have one file, you can obviously just use
Code:
$ g++ program.cpp -o program
This preprocesses your source, compiles it, and links it. You can stop the compiler after each of these steps, and one common procedure is to have one command preprocess and compile, and another link.
Code:
$ g++ -c program.cpp # -o program.o is optional
$ g++ program.o -o program
Of course, this works well with multiple source files too; you can compile each file with -c, and combine them all together with a "link" g++ command.
Code:
$ g++ -c file1.cpp
$ g++ -c file2.cpp
$ g++ file1.o file2.o -o program
However, you can also combine .cpp and .o files in one command line! g++ doesn't care. It just has to do more work when it sees a .cpp file. Also, there's rarely any need to invoke ld manually (although you can if you want). Just saying
Code:
$ g++ file1.o file2.o -o program
is sufficient to link object files together, and it has the added benefit of noticing C++ source files or assembly files and just dealing with them.
Finally: you can debug all of this yourself if you have the tools to do so. Specifically, "nm" will list all the symbols in an object file. If the symbol looks just like the function name, it's compiled as a C symbol; if it looks mangled, it's compiled as C++. Really, "mangled" is the technical term. Here's an example.
Code:
$ cat code.c
int func() { return 42; }
$ gcc -c code.c
$ nm code.o
0000000000000000 T func
$ cp code.c code.cpp
$ g++ -c code.cpp
$ nm code.o
0000000000000000 T _Z4funcv
$
The name of the first symbol is "func", which is clearly not mangled. But "_Z4funcv" is mangled. So you can tell whether C or C++ symbols are being put into the file. extern "C" should put a C symbol into the file (so that you can call it from C); if you're getting undefined references to "_Z4funcv" or whatever then there's no extern "C" in the header file. If you don't have extern "C" in the source file then the symbol will be mangled and you won't be able to call it from C.
There's a useful utility called c++filt that can unmangle symbols for you if they become unreadable: try "nm file.o | c++filt". If you're curious about this stuff, look up "ldd" too, it's pretty useful.
Finally, the order you specify files in for the g++ command line should only matter for libraries; you can put individual .o files in any order you want. I'm pretty sure of this. Otherwise just about every Makefile ever written would get random linker errors.