Author Topic: Help creating a static library  (Read 2838 times)

kaykun

  • Guest
Help creating a static library
« 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?
« Last Edit: February 15, 2010, 06:34:36 am by kaykun »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Help creating a static library
« Reply #1 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
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ