Creating a Library - Visual Studio 2010

Hello,

I'm programming C++ in Visual Studio 2010.

I would like to create a library so I can just write:
#include <functions.h>
and not have to re-write all the functions every time.

1. Can you please help me understand how that works?
2. I saw videos of this on YouTube but I don't understand what they are doing and how to make it work once I've done it.

Thank you.
Last edited on
create a header file in a file location relative to the make file. here is a really really simple example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
//  Header.h
//  test
//
//  Created by Home on 4/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef test_Header_h
#define test_Header_h
//my header
#include <iostream> 
//included library
class me{
private://variables here
    int a, b;
public://functions here
    int returnA(){return a;}
    int returnB(){return b;}
    me();
}
me::me(){//contructor; 
    int a = 10;
    int b = 10;
}

#endif 
So I need to create a head file in the same directory of my "Solution" and that's it?
Ok I think I got it but now I get an error:

Error 2 error LNK2019: unresolved external symbol "void __cdecl insertDataToEndList(struct list &,int)" (?insertDataToEndList@@YAXAAUlist@@H@Z) referenced in function _main D:\Dropbox\Semester II\Data Structures\Visual Studio\Targil_4\testing\testing.obj
after you create the main.cpp there should be an option to create a file with it. then select header file. remember when including the header you need to do
#include "headername.h"
Create a file with in the main??

Here is what I did so far:

1. Created a headername.h file and put it in the project folder.
2. Created a headername.cpp file and put in the project folder.
3. The CPP file has #include "headername.h" in it.

What am I missing?

p.s.
This is really driving me crazy, thanks for the help.
1. Created a headername.h file and put it in the project folder.
2. Created a headername.cpp file and put in the project folder.
3. The CPP file has #include "headername.h" in it.


4. Build that project as a static library. You get a *.lib file out.
5. When you want to use that library in another project:
a). #include the header file (which will need to be in your new project directory etc)
b). Tell the linker you want to link against the lib file (give it the name)
c). Tell the linker where to find the lib file (give it the directory)
I've tried fallowing what you guys said to do but I don't seem to understand what ur even saying.

Can you please explain it a bit more simple?
Topic archived. No new replies allowed.