I have GradeBook.h that include class interface, GradeBook.cpp that include class implemantation, I want to make a lib file and use it with GradeBook.h on the other project. How can I do that ?
I am using Windows 7, VS 2008
I have GradeBook.h that include class interface, GradeBook.cpp that include class implemantation, I want to make a lib file and use it with GradeBook.h on the other project. How can I do that ?
I am using Windows 7, VS 2008
Short summary: the static .lib route that recommended is the simplest for reusing a C++ class. What often gets missed after the basic add‑include/add‑lib steps that already did are a handful of compatibility and packaging details that cause link or runtime failures later.
A few practical points not covered above: a Windows *.lib can be either a true static library (code baked into the EXE at link time) or an import library that forwards to a DLL (which requires the DLL at runtime). If a DLL is desired, the header must mark exported symbols; as hinted, the header typically needs a small macro so the same header compiles for both the DLL build and the clients. Example pattern:
#ifdef GRADEBOOK_EXPORTS
#define GRADEBOOK_API __declspec(dllexport)
#else
#define GRADEBOOK_API __declspec(dllimport)
#endif
class GRADEBOOK_API GradeBook { ... }; Keep build configurations in sync: the consumer project should use the same architecture (Win32 vs x64), the same Visual C++ toolset/version, and compatible runtime-library settings (/MD vs /MT and Debug vs Release). Mismatched CRT settings or compiler versions are common causes of subtle crashes or linker errors. Templates and inline functions deserve special attention — templates generally must remain in headers unless explicitly instantiated in the library build.
Quick troubleshooting checklist (after the basic include/lib settings are correct): verify whether the .lib is an import or static lib (presence of a same‑named DLL and the size can help), ensure export macros are defined when building the DLL, match runtime/architecture/configuration, and inspect unresolved externals for name‑mangling issues (extern "C" for C APIs). When distributing the library, include headers plus separate lib files for each configuration (Debug/Release, x86/x64) and document the required runtime.
Jump to Post— Fbody 682I would store the files in a location easily accessible from both projects then include them in the project(s) respective solutions...
Unless you're trying to make a DLL or something, then I can't help you...
Jump to Post— Fbody 682If I want to make a dll from GradeBook.h GradeBook.cpp. How I can do it and How Can I use this dll with GradeBook.h on the other project ?
I unfortunately can't help you with that. I know you will still need a modified version of GradeBook.h so that you …
Jump to Post— Fbody 682This link is very helpful I think I will do what I want. I am trying the instructions on the link.
http://msdn.microsoft.com/en-us/library/ms235627.aspxThx for the link. I actually have a downloaded copy of the …
I would store the files in a location easily accessible from both projects then include them in the project(s) respective solutions...
Unless you're trying to make a DLL or something, then I can't help you...
I would store the files in a location easily accessible from both projects then include them in the project(s) respective solutions...
Unless you're trying to make a DLL or something, then I can't help you...
If I want to make a dll from GradeBook.h GradeBook.cpp. How I can do it and How Can I use this dll with GradeBook.h on the other project ?
If I want to make a dll from GradeBook.h GradeBook.cpp. How I can do it and How Can I use this dll with GradeBook.h on the other project ?
I unfortunately can't help you with that. I know you will still need a modified version of GradeBook.h so that you have an interface for your program and that GradeBook.cpp will compile into the actual DLL with the proper modifications. However, I do not know the required syntax. I'm very much a newb in that department.
I unfortunately can't help you with that. I know you will still need a modified version of GradeBook.h so that you have an interface for your program and that GradeBook.cpp will compile into the actual DLL with the proper modifications. However, I do not know the required syntax. I'm very much a newb in that department.
This link is very helpful I think I will do what I want. I am trying the instructions on the link.
http://msdn.microsoft.com/en-us/library/ms235627.aspx
This link is very helpful I think I will do what I want. I am trying the instructions on the link.
http://msdn.microsoft.com/en-us/library/ms235627.aspx
Thx for the link. I actually have a downloaded copy of the MSDN Library, I just haven't gotten to/through this part yet.
I did the library file with a lib project.
Lib project:
Fıle->new->project.... On Application Settings windows I chose static library and empty project settings and built it.
vs2008
But on the link, it is making a the project that is using the lib project. That is useless. The project should use just the lib file not the project.
note lib project: that only include header file and cpp file that includes only class implementation.
If all you want to share is a header file and *.cpp file then I wouldn't bother making a DLL because that is like killing a fly with a sludgehammer. Instead, just create a static library project and add those two files to it. Then in each of the application programs just link with that library.
If all you want to share is a header file and *.cpp file then I wouldn't bother making a DLL because that is like killing a fly with a sludgehammer. Instead, just create a static library project and add those two files to it. Then in each of the application programs just link with that library.
I did the lib file from header file and the cpp(I built them when the project is a static library) I don't want to make a dll too. How can I link that .lib file when I make other projects ?
I did linking.
1. Tools/Options/Projects and Solutions/VC++ directories/
Platform "Win32" ShowDirectories for "library files"
and I added the folder to here that include my .lib file.
2. Project/ "your project" properties/ Configuration Properties/Linker/Input/Additional Dependencies
and I added my lib file "lib.lib" to here
that is it.
and If you want to use a *.h file that is made before in your project without add the header file to your project (just #include it in main)
and add here your folder that include your header file.
and you can now built your project without header and source file(class implementation) just with a main.cpp file.
#include"GradeBook.h"
int main()
{
GradeBook grade1("sdgdg");
grade1.displayMessage();
return 0;
}
#include"GradeBook.h" this is wrong sorry :(probably the project will be built with no errors)
#include<GradeBook.h> that will be true way Because this file is'nt in the project folder it is in a folder that you specified in Project/ "your project" properties/ Configuration Properties/C/C++/Additional Include Directories
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.