Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: kaykun on February 15, 2010, 06:16:31 am

Title: Help creating a static library
Post by: kaykun on February 15, 2010, 06:16:31 am
Hi all, my first question is why does a static library rely on a executable to be compiled? I'm trying to create a simple static library and this is my program source:

Code
#include <windows.h>

int SampleAddInt(int i1, int i2);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    int hi=1,hi2=2;

    SampleAddInt(hi, hi2);

    return 0;
}

So first I compiled the program without the "SampleAddInt(hi, hi2);" and used it to compile the static library.

I used the default static library when creating one with code blocks:

Code
int SampleAddInt(int i1, int i2)
{
    return i1 + i2;
}

// A function doing nothing ;)
void SampleFunction1()
{
    // insert code here
}

// A function always returning zero
int SampleFunction2()
{
    // insert code here
   
    return 0;
}

I linked the compiled library to the program, and I can't compile the main program with the "SampleAddInt(hi, hi2);" getting this error: undefined reference to `SampleAddInt(int, int)'|

Does anybody know why this error happens?
Title: Re: Help creating a static library
Post by: MortenMacFly on February 15, 2010, 06:34:44 am
Would you please accept our forum rules and search before you post?
This has been answered many times, the last time a few days ago here:
http://forums.codeblocks.org/index.php/topic,12001.0.html