Please help I search throw whole internet but I can\'t find answer ...
I have created simple function int mean(int, int);
and place i
Simply use C compiler instead!
You compile with C++ compiler (Makefile has "$(GPP) -c *.c") and the function symbol name includes parameter information and is called different: not "mean", but something more complex, similar as Java names symbols internally. You can use "nm" to see what's inside an object file.
For example my g++ generates:
# nm x.o
00000000 T _Z4meanii
So there is no "mean" (but "Z4meanii"). Using a C compiler, and the symbol names are straightforward:
# nm x.o
00000000 T mean
(Please note that the same source code content was compiled)
So change in you Makefile:
obj:
$(GCC) -c *.c
If for some reason a C++ compiler must be used, then extern "C" must be added:
calc_mean.h (simplified, without inclusion guards etc.)
#ifdef __cplusplus
extern "C" {
#endif
int mean(int, int);
#ifdef __cplusplus
} // extern "C"
#endif
In general, if you need C symbol names in C++ files, use extern "C". Test_Library.h uses it correctly and provides a nice example. You can put the same extern "C" logic (best including if #ifdef __cplusplus block) to your header file. Some consider it good practice to always do so.
But note that there are several, sometimes subtle, differences between C and C++, so I recommend to compile C sources with C compiler, although I know that there can be advantages using a C++ compiler.
oki,
Steffen