赞
踩
1、showCpp.cpp
- #include <iostream>
- using namespace std;
-
- // 声明为C语言可以调用的函数
- extern "C" void ShowCPP()
- {
- cout<<"I'm printed by CPP codes."<<endl;
- }
- #include <stdio.h>
- void Show()
- {
- printf("Hello, I'm printed by C code.\n");
- // 调用C++函数
- ShowCPP();
- }
- // 声明Show函数为C语言编写的函数
- extern "C" void Show();
-
- int main()
- {
- // 调用C语言编写的函数
- Show();
-
- return 0;
- }
5、编译codeofC.c得到文件codeofC.o
6、链接showCpp.o和codeofC.o得到静态库文件libcodeofC.a
7、编译codeofCPP.cpp并使用库文件libcodeofC.a得到可执行程序 ”-L. “表示库文件所在位置为当前目录,”-lcodeofC “表示库文件libcodeofC.a
8、程序运行:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。