Error while trying to make library in code blocks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • puneetsardana88
    New Member
    • Aug 2009
    • 57

    Error while trying to make library in code blocks

    Hi

    I tried to make a library using code blocks. For which I went file->new->project->static library and name it as mylib and then i created a file mylib1.c and mylib1.h (with some sample functions in it like Swap) and build them. Now I again make another project hello in which i make a file main.c in which I included lib1.h. When i tried to run the program i got the message "please select the host to run the library" something like that. Then i google it and then i went to project->build options->linker setting and then i add ..\mylib\libmyl ib.a. After that i got the error

    lib1.h-No such file or directory.

    What should i do?

    Here is the code

    For library

    lib1.c
    Code:
    // The functions contained in this file are pretty dummy
    // and are included only as a placeholder. Nevertheless,
    // they *will* get included in the static library if you
    // don't remove them :)
    //
    // Obviously, you 'll have to write yourself the super-duper
    // functions to include in the resulting library...
    // Also, it's not necessary to write every function in this file.
    // Feel free to add more files in this project. They will be
    // included in the resulting library.
    
    // A function adding two integers and returning the result
    int SampleAddInt(int i1, int i2)
    {
        return i1 + i2;
    }
    
    // A function doing nothing ;)
    void Swap(int *a , int *b)
    {
        *a=*a+*b;
        *b=*a-*b;
        *a=*a-*b;
    }
    
    // A function always returning zero
    int Increa(int x)
    {
        return ++x;
    
        return 0;
    }
    lib1.h

    Code:
    void Swap(int *a , int *b);
    int Increa(int x);
    int SampleAddInt(int i1, int i2);
    Then another project Hello i made main.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include"lib1.h"
    int main()
    {
        int a=1,b=2;
        Swap(&a,&b);
        printf("%d  %d",a,b);
        return 0;
    }

    What should i do?I am using codeblocks with mingw under windows?

    I have attached the screenshot also
    Attached Files
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Where is lib1.h located?

    When you #include "lib1.h" it means that lib1.h is in the same directory as main.c OR lib1.h is in a directory that is along a pre-defined path.

    When you #include <lib1.h>, it means that lib1.h is in a directory that is along a pre-defined path.

    It looks like top need to pre-define a path. Go to your project settings for the preprocessor. It tis there you can specify additional directories for include files.

    Comment

    • puneetsardana88
      New Member
      • Aug 2009
      • 57

      #3
      Coulnt find these options........ ....


      Please see the screenshot...
      Attached Files

      Comment

      • puneetsardana88
        New Member
        • Aug 2009
        • 57

        #4
        Ok After 1 hours of searching and testing I have been able to execute it. Now the question is to the other party we only give header files. So how can I organize libraries

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          No you will need to supply them with the header and the .a file.

          What do you mean how do you organise libraries? Just pass them over the other party can put them in a convenient directory and link them into their program.

          Comment

          • macerau
            New Member
            • May 2020
            • 1

            #6
            Originally posted by puneetsardana88
            Ok After 1 hours of searching and testing I have been able to execute it. Now the question is to the other party we only give header files. So how can I organize libraries
            Since you spent time figuring out the solution, why not share it?
            didn't you come here to get someone's solution?

            Comment

            Working...