1、用GCC编译
1.1、创建源文件
-
(main.c) C 源文件 - main.c
#include #include “reciprocal.hpp” int main (int argc, char **argv) { int i; i = atoi (argv[1]); printf (“The reciprocal of %d is %g/n”, i, reciprocal (i)); return 0; } |
-
(reciprocal.cpp) C++ 源文件 - reciprocal.cpp
#include #include “reciprocal.hpp” double reciprocal (int i) { // I should be non-zero. assert (i != 0); return 1.0/i; } |
-
(reciprocal.hpp) 头文件 - reciprocal.hpp
#ifdef __cplusplus extern “C” { #endif extern double reciprocal (int i); #ifdef __cplusplus } #endif |
1.2、编译源文件
-
编译main.c:
% gcc -c main.c |