Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************/
- // 1.h
- #ifdef __cplusplus
- extern "C" {
- #endif
- int func(int a, int b);
- #ifdef __cplusplus
- }
- #endif
- /******************************************************/
- // 1.cpp
- #include "1.h" // 必须加这个头文件,这样才能编译成C符号!!否则会链接失败
- int func(int a, int b)
- {
- return a * b;
- }
- /******************************************************/
- // main.c
- #include <stdio.h>
- #include "1.h"
- int main()
- {
- printf("result=%d\n", func(123, 10));
- return 0;
- }
- /******************************************************/
- // Makefile
- main:
- g++ -c 1.cpp
- gcc -c main.c
- g++ 1.o main.o -o main
- clean:
- rm -rf *.o main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement