delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/19/15:13:40

Message-ID: <33F9EFDA.31CC@nf.sympatico.ca>
Date: Tue, 19 Aug 1997 16:41:22 -0230
From: Colin Walsh <cwalsh AT nf DOT sympatico DOT ca>
Reply-To: cwalsh AT nf DOT sympatico DOT ca
Organization: Colossal Software
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
CC: djgpp AT delorie DOT com
Subject: Re: Creating Class Libraries
References: <33F9EE76 DOT 7A91 AT nf DOT sympatico DOT ca>

Oops, forgot to put it on the Mailing list....

I have tried recently to create libraries supporting all of the
filetypes that I keep creating for my various projects, but a problem
has come up. I want the libs to use classes, but they wont compile
properly.

Here is the source that loads .CGR (Colossal GRaphics)
#include <fstream.h>
#include <malloc.h>
#include <grx20.h>
class cgrfile{
        protected:
                unsigned char *cgrdata;
                long w,h;
        public:
                cgrfile()
                {
                        cgrdata=(unsigned char *)malloc(0);
                        w=0;
                        h=0;
                }
                void cgrload(char *filename,int palswitch)
                {
                        unsigned char bit;
                        unsigned char RGB[3];
                        fstream cgr(filename,ios::in|ios::binary);
                        cgr.read((char *)&w,sizeof(long));
                        cgr.read((char *)&h,sizeof(long));
                        cgrdata=(unsigned char *)realloc((void
*)cgrdata,w*h);
                        if(palswitch==0)//dont load the palette
                        {
                                for(int x=0;x<256;x++)
                                {
                                        cgr.read(RGB,3);
                                }
                        }
                        if(palswitch==1)//load the palette
                        {
                                for(int x=0;x<256;x++)
                                {
                                        cgr.read(RGB,3);
                                       
GrSetColor(x,RGB[0],RGB[1],RGB[2]);
                                }
                        }
                        for(long x=0;x<w*h;x++)
                        {
                                cgr.get(bit);
                                cgrdata[x]=bit;
                        }
                }
                void display()
                {
                        long pos=0;
                        for(long x=0;x<w;x++)
                        {
                                for(long y=0;y<h;x++)
                                {
                                        GrPlot(x,(h-1)-y,cgrdata[pos]);
                                        pos++;
                                }
                        }
                }
};

And this is the batch (too bothersome to create make files w/ dos
edit(not proper Tab)) file:

gcc -c cgr.cpp -o cgr.o
ar rvs libcgr.a cgr.o
copy libcgr.a \proglang\djgpp\lib

When the COFF file is created, it is waaay too small (365 bytes) to have
all this code.
I was wondering if anyone can tell me what needs to be changed so it
compiles properly, and yes...
I have read the FAQ on compiling libraries, but there is no info on how
you compile a class library.

Thanks for any help,
Colin Walsh
President/CEO/Dictator for life :), Colossal Software

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019