Advertisement
devincpp

extern__cpp_code_call_c_function

Apr 11th, 2025
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. /******************************************************/
  2. // 1.h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7.     int func(int a, int b);
  8.  
  9. #ifdef __cplusplus
  10. }
  11. #endif
  12.  
  13.  
  14. /******************************************************/
  15. // 1.c
  16. // #include "1.h"  // 这个头文件可以不加
  17.  
  18. int func(int a, int b)
  19. {
  20.     return a * b;
  21. }
  22.  
  23.  
  24. /******************************************************/
  25. // main.cpp
  26. #include <stdio.h>
  27. #include "1.h"
  28.  
  29. int main()
  30. {
  31.     printf("result=%d\n", func(123, 10));
  32.  
  33.     return 0;
  34. }
  35.  
  36.  
  37. /******************************************************/
  38. // Makefile
  39. main:
  40.     gcc -c 1.c
  41.     g++ -c main.cpp
  42.     g++ 1.o main.o -o main
  43.  
  44. clean:
  45.     rm -rf *.o main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement