The corresponding. C and dot. h files are as follows:
C.c
#include "cplus.hpp"
#include "c.h"
A *a = new B ();
void Test ()
{
// A *a = new B ();
A->test ();
}
Cplus.cpp
#include <iostream>
#include <string>
#include "cplus.hpp"
using namespace std;
void A::test ()
{
cout<< "A" <<endl;
}
void B::test ()
{
cout<< "B" <<endl;
}
C.h
#ifndef _c_h_
#define _C_H_
#ifdef __cplusplus
extern "C" {
#endif
void Test ();
#ifdef __cplusplus
}
#endif
#endif
Cplus.hpp
Class a{public
:
virtual void Test ();
Class B:public a{public
:
void Test ();
The makefile for generating the dynamic link library is as follows
cxx=g++
cxxflags=-c
#INCLUDE =
#LIB =
#SUBLIB =
target_name=libc_test.so
$ (target_name): C.O CPLUS.O
$ (CXX)-fpic-shared-o $@ $^ c.o:c.c c.h cplus.hpp
$ (CXX)-fpic-c
$^ cplus.o:cplus.cpp cplus . HPP
$ (CXX)-fpic-c $^ clean
:
rm *.o
RM *.GCH
RM $ (target_name)
The makefile for generating a static link library is as follows
cxx=g++
cxxflags=-c
#INCLUDE =
#LIB =
#SUBLIB =
AR = ar-r
target_name=libc_test.a
$ (target_name): C.O cplus.o
$ (AR) $@ $^ c.o:c.c c.h cplus.hpp
$ (CXX)-C $^
Cplus.o:cplus.cpp CPLUS.HPP
$ (CXX)-C $^ Clean
:
rm *.o
RM *.GCH
RM $ (target_name)