sample code is here~~~~~~~~

scorpio (scorpio)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
enc lib: enc.h/codec.cpp/cod.h/cod.cpp with a define "_ENC_LIB_"
dec lib: dec.h/codec.cpp/cod.h/cod.cpp with a define "_DEC_LIB_"
exe: test.cpp/dec.h/enc.h

VC reports link error with this code: cod::cod()/cod::~cod()/cod::read_file()
already defined. but everything is ok when I delete #ifdef in cod.cpp/cod.h,
why? anyway to resolve it if I really want those #ifdef? real source is
really big so please dont tell me to duplicate functions.

thanks,

///////////////////////////////////////////////////////
//cod.cpp
#include "stdio.h" #include "cod.h"
cod::cod(){} cod::~cod(){} void cod::read_file(){ printf("cod::read_file\n");}
#ifdef _DEC_LIB_ void cod::dec(){ printf("cod::dec\n");} #endif
#ifdef _ENC_LIB_ void cod::enc(){ printf("cod::enc\n");} #endif

//codec.cpp
#include "codec.h" #include "cod.h"
#ifdef _DEC_LIB_ dec::dec(){ pdec = new cod; ((cod *)pdec)->read_file();}
dec::~dec(){ delete pdec;} void dec::decode(){ ((cod *)pdec)->dec();}
#endif
#ifdef _ENC_LIB_ enc::enc(){ penc = new cod; ((cod *)penc)->read_file();}
enc::~enc(){ delete penc;} void enc::encode(){ ((cod *)penc)->enc();}
#endif

//dec.h
#ifndef enc_h #define enc_h
class enc{ public: void *penc; enc(); ~enc(); void encode();}; #endif

//enc.h
#ifndef enc_h #define enc_h
class enc{ public: void *penc; enc(); ~enc(); void encode();}; #endif

//test.cpp
#include "enc.h" #include "dec.h"
#pragma comment(lib, "enc.lib") #pragma comment(lib, "dec.lib")
void main(){ enc e; e.encode(); dec d; d.decode();}
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
(#88659@0)
2001-6-3 -05:00

回到话题: help help! 怎么在一个EXE里连两个STATIC LIBRARY?这两个LIB SHARE一些FUNCTION,我联的时候VC报错:a.lib: function xyz is already defined in b.lib.

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=88659