By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,028 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,028 IT Pros & Developers. It's quick & easy.

Error while trying to make library in code blocks

P: 57
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\libmylib.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
Expand|Select|Wrap|Line Numbers
  1. // The functions contained in this file are pretty dummy
  2. // and are included only as a placeholder. Nevertheless,
  3. // they *will* get included in the static library if you
  4. // don't remove them :)
  5. //
  6. // Obviously, you 'll have to write yourself the super-duper
  7. // functions to include in the resulting library...
  8. // Also, it's not necessary to write every function in this file.
  9. // Feel free to add more files in this project. They will be
  10. // included in the resulting library.
  11.  
  12. // A function adding two integers and returning the result
  13. int SampleAddInt(int i1, int i2)
  14. {
  15.     return i1 + i2;
  16. }
  17.  
  18. // A function doing nothing ;)
  19. void Swap(int *a , int *b)
  20. {
  21.     *a=*a+*b;
  22.     *b=*a-*b;
  23.     *a=*a-*b;
  24. }
  25.  
  26. // A function always returning zero
  27. int Increa(int x)
  28. {
  29.     return ++x;
  30.  
  31.     return 0;
  32. }
  33.  
lib1.h

Expand|Select|Wrap|Line Numbers
  1. void Swap(int *a , int *b);
  2. int Increa(int x);
  3. int SampleAddInt(int i1, int i2);
  4.  
Then another project Hello i made main.c
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include"lib1.h"
  4. int main()
  5. {
  6.     int a=1,b=2;
  7.     Swap(&a,&b);
  8.     printf("%d  %d",a,b);
  9.     return 0;
  10. }
  11.  

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

I have attached the screenshot also
Attached Images
File Type: jpg untitled.jpg (15.2 KB, 770 views)
Dec 15 '09 #1
Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Dec 15 '09 #2

P: 57
Coulnt find these options............


Please see the screenshot...
Attached Images
File Type: jpg untitled.jpg (15.9 KB, 271 views)
Dec 15 '09 #3

P: 57
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
Dec 15 '09 #4

Banfa
Expert Mod 5K+
P: 8,949
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.
Dec 15 '09 #5

P: 1
@puneetsardana88
Since you spent time figuring out the solution, why not share it?
didn't you come here to get someone's solution?
May 31 '20 #6

Post your reply

Sign in to post your reply or Sign up for a free account.