Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, just a quick question i have,
suppose i have a c++ console app project.
it has some class:
C++
class A
{
public:
 void printHello();
}


then in the same console project, i got:
C++
void main()
{
  A a;
  a.printHello();
}


this project is closed and cant be touched.

now, i'm creating a new project, and i want to use only the A class in there.
can i do it? shouldnt i get a .Lib file somehow?

thanks.
Posted
Updated 25-Dec-11 0:50am
v2

Assuming you are using Visual Studio, read this elementary article on creating and using DLLs in C++ with Visual Studio, this will be quite enough to start with:
http://msdn.microsoft.com/en-us/library/ms235636%28v=vs.80%29.aspx[^].

This is 2005, but totally valid for any later version of Visual Studio. If you are not using Visual Studio, it will be helpful anyway. You can find a lot more articles on this elementary topic.

—SA
 
Share this answer
 
Comments
arielbeck 8-Feb-12 1:30am    
not what i've asked.
i know how to do this, so u guess it needs to be recompiled as a lib.
You have to link the code to a DLL or directly into your application. General practice is to put common code into a DLL (that's what they're for), and then you can access the classes in the DLL.
 
Share this answer
 
Comments
arielbeck 25-Dec-11 7:00am    
ye i know its not a common practice, but i just wondered.
so you say that the console project must be touched to change the output to lib, right?
Hi,

In order to generate Lib, you have to create a Win32 console application with application type as "Static Library".After compiling the project, you will get the concerned lib in "Debug" or "Release" folder.
In order to reuse the "Lib" file you should specify it in the Linker options of the new project, and add the concerned header file also.If you need to reuse the resource also, convenient to make it a DLL.


Thanks
 
Share this answer
 
Wouldn't creating a library imply that you need access to the code?
If so you might just as well include the class in a the new application.
 
Share this answer
 
Comments
JackDingler 27-Dec-11 10:59am    
If you have an assortment of projects accessing a shared code base, making copies of the files with every change becomes unwieldy and error prone.

Putting the common code in libraries gives you one central place to make changes to the class.

This way you don't have to search your projects, and make the same changes over and over, every time you update your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900