- 论坛徽章:
- 0
|
Ok, let's go ahead. as for *.cpp project you should need the extern "C" only if you are calling a C function , vice versa, you should do the same for *.c project . for instance
b.cpp
- #include "a.h"
- typedef AList<int> iA;
- iA x;
- #ifdef __cplusplus
- extern "C" {
- #endif
- void OutputInfo()
- {
- x.display(10);
- }
- #ifdef __cplusplus
- }
- #endif
复制代码
main.c
- #include <stdio.h>
- #include <stdlib.h>
- extern void OutputInfo();
- int main()
- {
- OutputInfo();
- exit(0);
- }
复制代码
The result of compilation
- $ gcc -c b.cpp -o b.o
- $ gcc -c main.c -o main.o
- $ gcc -o bin main.o b.o
- b.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
- collect2: ld returned 1 exit status
- $
复制代码
I mean that you need extern "C" only if you are calling a fcuntion which be implemented within *.C/.cpp/.cc
[ 本帖最后由 SybaseLU 于 2007-8-7 11:45 编辑 ] |
|