News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Help creating a static library

Started by kaykun, February 15, 2010, 06:16:31 AM

Previous topic - Next topic

kaykun

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:

#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:


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?

MortenMacFly

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.next.codeblocks.org/index.php/topic,12001.0.html
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]