Click here to Skip to main content
11,920,413 members (55,974 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++
Hey, just a quick question i have,
suppose i have a c++ console app project.
it has some class:
class A
 void printHello();

then in the same console project, i got:
void main()
  A a;

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?

Posted 25-Dec-11 1:41am
Edited 25-Dec-11 1:50am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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:[^].

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.

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 4

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.
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)

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web01 | 2.8.151120.1 | Last Updated 26 Dec 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100