对原integerArithmetic库进行改写,重新生成fblib:包含5个文件,fbh,funset.h,renamh,root.h和funset.cpp,fbh为上层提供的接口;
#ifndef _FUNSET_H_
#define _FUNSET_H_
int add(int a, int b);
int sub(int a, int b);
int mul(int a, int b);
int pision(int a, int b);
#endif //_FUNSET_H_
#include 'root.h'
int add(int a, int b)
{
return (a + b) / 2;
}
int sub(int a, int b)
{
return (a - b) / 2;
}
int mul(int a, int b)
{
return (a * b) / 2;
}
int pision(int a, int b)
{
if (b == 0) return -1;
return (a / b) / 2;
}
#ifndef _DONT_RENAME_
//To avoid any possible linking confliction, rename all exported names
#define add RENAME_add
#define sub RENAME_sub
#define mul RENAME_mul
#define pision RENAME_pision
#endif //!_DONT_RENAME_
#ifndef _ROOT_H_
#define _ROOT_H_
#include 'rename.h'
#include 'funset.h'
#endif //_ROOT_H_
#include 'root.h'
#define fbc_add add
#define fbc_sub sub
#define fbc_mul mul
#define fbc_pision pision
新建一个testRename控制台工程,测试这两个库,包含6个文件:testfbh,testfbcpp,testintegerArithmetih,testintegerArithmeticpp,stdafx.cpp,testRenamcpp:
#ifndef _TEST_FBC_H_
#define _TEST_FBC_H_
void cal_fbc(int a, int b);
#endif //_TEST_FBC_H_
#include 'stdafx.h'
#include 'testfbc.h'
#include '../fbc/fbc.h'
#include
using namespace std;
void cal_fbc(int a, int b)
{
cout<<'test fbc lib:'<#ifndef _TEST_INTEGER_ARITHMETIC_H_
#define _TEST_INTEGER_ARITHMETIC_H_
void cal_integerArithmetic(int a, int b);
#endif//_TEST_INTEGER_ARITHMETIC_H_
#include 'stdafx.h'
#include 'testintegerArithmetic.h'
#include '../integerArithmetic/funset.h'
#include
using namespace std;
void cal_integerArithmetic(int a, int b)
{
cout<<'test integerArithmetic lib:'<#include 'stdafx.h'
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
#pragma comment(lib, '../debug/fbc.lib')
#pragma comment(lib, '../debug/integerArithmetic.lib')
#include 'stdafx.h'
#include
#include 'testintegerArithmetic.h'
#include 'testfbc.h'
using namespace std;
int main(int argc, char* argv[])
{
int a, b;
a = 10;
b = 2;
cal_integerArithmetic(a, b);
cal_fbc(a, b);
cout<<'ok'<首先模拟一个简单的开源库integerArithmetilib,实现简单的整数加、减、乘、除运算:包含2个文件,funset.h和funset.cpp,作为上层直接调用;
#ifndef _FUNSET_H_
#define _FUNSET_H_
int add(int a, int b);
int sub(int a, int b);
int mul(int a, int b);
int pision(int a, int b);
#endif //_FUNSET_H_
#include 'funset.h'
int add(int a, int b)
{
return (a + b);
}
int sub(int a, int b)
{
return (a - b);
}
int mul(int a, int b)
{
return (a * b);
}
int pision(int a, int b)
{
if (b == 0) return -1;
return (a / b);
}
使用dumpbin工具查看fbclilib,SymbolName分别为RENAME_add,RENAME_sub,RENAME_mul,RENAME_pision;而integerArithmetilib中SymbolName分别为add,sub,mul,pision,所以不会产生冲突。
文章为作者独立观点,不代表股票交易接口观点