Hi all, first post, please be gentile.....

I was doing an online tutorial on creating a simple library to generate .svg files. Sadly, the tutorial has disappeared from the 'net so I can't provide a direct link to it, but I don't think that is needed. I think this is a simple problem, but above my c knowledge.

There are 3 files created doing the tutorial. The first is main.c

Code:
#include<stdio.h>
#include<math.h>
#include<time.h>

#include"svg.h"


//--------------------------------------
// FUNCTION PROTOTYPES
//--------------------------------------
void drawrectangles(void);
void drawallshapes(void);
void iwanttobelieve(void);
void mondrian(void);


//--------------------------------------
// FUNCTION main
//--------------------------------------
int main()
{
    puts("Code in C - SVG\n---------------\n");

    drawrectangles();

    //drawallshapes();

    //iwanttobelieve();

    //mondrian();

    return EXIT_SUCCESS;
}


// -------------------------------------
// FUNCTION drawrectangles
// -------------------------------------
void drawrectangles(void)
{
    svg* psvg;
    psvg = svg_create(512, 512);

    if(psvg == NULL)
    {
        puts("psvg is NULL");
    }
    else
    {
        svg_rectangle(psvg, 512, 512, 0, 0, "white", "white", 0, 0, 0);

        svg_rectangle(psvg, 384, 384, 64, 64, "#00FF00", "#000000", 4, 0, 0);
        svg_rectangle(psvg, 320, 320, 96, 96, "#FFFF00", "#000000", 2, 8, 8);
        svg_rectangle(psvg, 256, 256, 128, 128, "#00FFFF", "#000000", 2, 8, 8);
        svg_rectangle(psvg, 192, 192, 160, 160, "#FF80FF", "#000000", 2, 8, 8);

        svg_finalize(psvg);
        svg_save(psvg, "rectangles.svg");
        svg_free(psvg);
    }
}
the second file created is the header file, svg.h

Code:
#include<stdlib.h>

#include<stdbool.h>

#include<stdio.h>

#include<math.h>


//-------------------------------------
// STRUCT svg
//-------------------------------------
typedef struct svg
{
    char* svg;

    int height;

    int width;

    bool finalized;

} svg;


//-------------------------------------
// FUNCTION PROTOTYPES
//-------------------------------------
svg* svg_create(int width, int height);

void svg_finalize(svg* psvg);

//void svg_print(svg* psvg);

void svg_save(svg* psvg, char* filepath);

void svg_free(svg* psvg);

//void svg_circle(svg* psvg, char* stroke, int strokewidth, char* fill, int r, int cx, int cy);

//void svg_line(svg* psvg, char* stroke, int strokewidth, int x1, int y1, int x2, int y2);

void svg_rectangle(svg* psvg, int width, int height, int x, int y, char*  fill, char* stroke, int strokewidth, int radiusx, int radiusy);

//void svg_fill(svg* psvg, char* fill);

//void svg_text(svg* psvg, int x, int y, char* fontfamily, int fontsize, char* fill, char* stroke, char* text);

//void svg_elipse(svg* psvg, int cx, int cy, int rx, int ry, char* fill, char* stroke, int strokewidth);
The third file is the svg.c file, and it's kinda long, forgive me...

Code:
#include<stdlib.h>

#include<stdbool.h>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include"svg.h"

//--------------------------------------
// STATIC FUNCTION appendstringtosvg
//--------------------------------------
static void appendstringtosvg(svg* psvg, char* text)
{
    int l = strlen(psvg->svg) + strlen(text) + 1;

    char* p = realloc(psvg->svg, l);

    if(p)
    {
        psvg->svg = p;
    }

    strcat(psvg->svg, text);
}


//--------------------------------------
// STATIC FUNCTION appendnumbertosvg
//--------------------------------------
static void appendnumbertosvg(svg* psvg, int n)
{
    char sn[16];

    sprintf(sn, "%d", n);

    appendstringtosvg(psvg, sn);
}


//--------------------------------------
// FUNCTION svg_create
//--------------------------------------
svg* svg_create(int width, int height)
{
    svg* psvg = malloc(sizeof(svg));

    if(psvg != NULL)
    {
        *psvg = (svg){.svg = NULL, .width = width, .height = height, .finalized = false};

        psvg->svg = malloc(1);

        sprintf(psvg->svg, "%s", "\0");

        appendstringtosvg(psvg, "<svg width='");
        appendnumbertosvg(psvg, width);
        appendstringtosvg(psvg, "px' height='");
        appendnumbertosvg(psvg, height);
        appendstringtosvg(psvg, "px' xmlns='http://www.w3.org/2000/svg'  version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink'>\n");

        return psvg;
    }
    else
    {
        return NULL;
    }
}


// -------------------------------------
// FUNCTION svg_finalize
// -------------------------------------
void svg_finalize(svg* psvg)
{
    appendstringtosvg(psvg, "</svg>");

    psvg->finalized = true;
}


//--------------------------------------
// FUNCTION svg_rectangle
//--------------------------------------
void svg_rectangle(svg* psvg, int width, int height, int x, int y, char*  fill, char* stroke, int strokewidth, int radiusx, int radiusy)
{
    appendstringtosvg(psvg, "    <rect fill='");
    appendstringtosvg(psvg, fill);
    appendstringtosvg(psvg, "' stroke='");
    appendstringtosvg(psvg, stroke);
    appendstringtosvg(psvg, "' stroke-width='");
    appendnumbertosvg(psvg, strokewidth);
    appendstringtosvg(psvg, "px' width='");
    appendnumbertosvg(psvg, width);
    appendstringtosvg(psvg, "' height='");
    appendnumbertosvg(psvg, height);
    appendstringtosvg(psvg, "' y='");
    appendnumbertosvg(psvg, y);
    appendstringtosvg(psvg, "' x='");
    appendnumbertosvg(psvg, x);
    appendstringtosvg(psvg, "' ry='");
    appendnumbertosvg(psvg, radiusy);
    appendstringtosvg(psvg, "' rx='");
    appendnumbertosvg(psvg, radiusx);
    appendstringtosvg(psvg, "' />\n");
}


// -------------------------------------
// FUNCTION svg_save
// -------------------------------------
void svg_save(svg* psvg, char* filepath)
{
    if(!psvg->finalized)
    {
        svg_finalize(psvg);
    }

    FILE* fp;

    fp = fopen(filepath, "w");

    if(fp != NULL)
    {
        fwrite(psvg->svg, 1, strlen(psvg->svg), fp);

        fclose(fp);
    }
}


//--------------------------------------
// FUNCTION svg_free
//--------------------------------------
void svg_free(svg* psvg)
{
    free(psvg->svg);

    free(psvg);
}
So heres the problem, when I compile this in codeblocks, I get an error in main.c
Basically, the first use of a library function is unknown, like it's not been declared.

If I change this line in main.c from this
Code:
#include"svg.h"
to this
Code:
#include"svg.c"
the code compiles and works fine. I'm using codeblocks as my IDE and I actually think that is where the problem is.

here's a screenshot

and the forum software won't allow me to attach an image...

But basically, in codeblocks, on the left side of the screen where you can access the files of the code you're working on, the svg.h file is grayed out, like it's not available, but yet I can work on the code.

I aplogize for the sloopiness of this post, but the lack of adding an image makes it harder to describe what I see...

Thanks for any help,
Randy



Header and Library help...-screenshot-16-jpg