Creating a .lib file in Visual C++ 2010 express

Hello!

I heard that I can create a .lib file in Visual C++ 2010 Express. I've created a new project, -> Win32 Project -> Static Library. Now, the IDE gave me a lot of files that are meaningless to me. For instance, at "External Dependencies" tab I have a file, called sdkddlver.h, in Header Files tab I have 2 headers: stdafs.h and targetever.h.

I just want to create a few functions and to export them as a .lib file. Also, I want to create a header file which should have the prototype of that functions. How can I do that? I know that I have to create a .cpp file (must be an executable) but I can just put the functions in that file? Without any declarations or something? Why do I need all those files that IDE gave me, named above???

Thank you respectfully.
Any ideas?
I can't say for VS210 express, but in VS2010 pro you open the properties for your project, and in configuration properties under General, change the configuration type from application (.exe) to static library (.lib)

When you compile your code you'll have a lib file in either the release or debug folder, and the (your project name).h file that you have written.

The other files VS2010 creates by itself, a google or MSDN/help of the filenames will give you help on those.

http://stackoverflow.com/questions/10539391/what-is-sdkddkver-h-for
Last edited on
I just want to create a few functions and to export them as a .lib file
Have you actually put your code in the project and built it?
Of course I did that. When I compile, it says like that:
Uneable to start program D:\...(the path of my project)...\vector_int.lib The specified file is an unrecognized or unsupported binary format

What should I do with that?
A .lib file is not intended to be executed directly, it usually just contains a colection of functions. If you don't know even this simple thing, them maybe creating a library is not for you.
Look, all I want is just to create that .lib file with my functions in it. I know that a .lib file contains a colection of functions. I really know that.

The thing is that when I build that main.cpp with my functions in it, I get the error below, I DON"T TRY TO EXECUTE A .lib FILE, I WANT TO CREATE IT.

And, as far as I understood, I can create a .lib file by building a cpp file (with my functions in it), placed in a Win 32 project (static library). I don't understand why is so unpleasant to create something so simple.

I've been messing with this problem for a few days and I can't figure it out.

Look, I don't like to stress you by repeating all those things over and over again. I don't like that either. But I am requesting you respectfully, to help me with that because is very important to me. If I figure this out, I won't stress you anymore, I promise.



Thank you respectfully.
Last edited on
The idea is this. Your source files will have .c extensions of C programs and .cpp extensions for C++ programs. You add these source files to the project. When you build it, it generates a .lib file, which is your static library.

So you wouldn't expect to add a .lib file, as that is what is generated.

When I asked, "Have you actually put your code in the project and built it?" I would expect you to add source code files with .c or .cpp extensions and optionally header files.
Yes, I've put my code in the project. More exactely:

I've add a source file, called main.cpp, with the following contents:

1
2
3
4
#include"stdafx.h"

int ADD(int a, int b)
{  return a+b; }


And a header - file, called functions.h, with the following contents:

1
2
3
4
5
6
7
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED

int ADD(int a, int b);


#endif 


I want it to be as easy as possible, that's the reason I have just one simple function.

Now, when I debug the main.cpp, it says like that:
Uneable to start program D:\...(the path of my project)...\vector_int.lib The specified file is an unrecognized or unsupported binary format

What am I doing wrong?

If I can't figure this out, I will put all my functions in a header file and this is it.
Sound like you are either pressing F5 or clicking the green arrow. Try just building with F7.
I've found a file named vector_int (is the name of my project) but with the extension Object File Library. That might be it?
It should have a .lib extension, sounds like you may not have enabled displaying extensions (they are not displayed by default). If I am correct you should enable displaying them.
Topic archived. No new replies allowed.