|
-
October 8th, 2003, 04:31 PM
#1
question about lib
Hello,
Can someone please explain to me what is the meaning of a library (*.lib) application?
How do I make one? does it have a main?
what is the entry point, how do I call a functions that are inside this lib
Thanks
avi123
-
October 8th, 2003, 05:17 PM
#2
lib
Hi avi123,
I typically use libraries for separating certain functionality of my application without cluttering things up within the main source code. I have libraries for stricly custom GUI's as well as communication. Considering I keep the libraries resident in memory during the application, so I don't bother using the dynamic version of my libraries (.dll), and having to load them when needed.
My libraries are typically a bunch of classes that can work in conjunction with any other library or application I maybe using at the time. The library (.lib) makes things nice when I move onto a different project, and don't want to rewrite everything. I simply link in the .lib, and make the calls.
There is no need for an entry point, similar to a .dll.
In order to use a library, or the functionality,all you need to do is link the .lib with your main application or code base.
Once you have linked the library, you can simply make function calls or direct access like you would anything else, granted you've included your #include<> directive.
Hope that helps.
nosplinters
-
October 9th, 2003, 01:51 PM
#3
Libraries can be loaded at runtime with LoadLibrary in windows or dlopen on linux.
exported functions can then be reached by loading them with GetProcAddress on windows and dlsym on linux.
They can have an unlimited number of entry points where executables only have one (main).
It's pretty easy to write libraries that export entire objects.
On linux libraries usually have a .so extension and are compiled with the -shared flag.
you export functions by enclosing them with extern "C"{} tags.
There's plenty of examples in the linux source to show you the way.
-
October 11th, 2003, 11:34 PM
#4
Hi All
I facing some difficulties with my application regarding implicitly and explicitly loading dynamic lib, hope you guys can help...
1. How can i implicitly link the xxxx.lib written in VC++ into Borland C++. My applicaiton in Borland C just couldnt link the xxxx.lib written in VC++, can anyone tell me what is the problem.
2. Because of this reason, i resort to explicitly load the dynamic DLL on run time via calling the API eg. loadlibrary("Xxxx.dll) , instead of linking the xxxx.lib after compilation.
By this way, i can call the library function written in my VC++ from Borland C++. However, i find this method is kind of troublesome and somehow do conflict with my other applicaiton in run time.
Is it possible to link xxxx.lib written in different C++ compiler, suchas Borland and VC? Thanks
BestRegards,
james goh
-
October 12th, 2003, 03:48 AM
#5
Originally posted by James Goh
Is it possible to link xxxx.lib written in different C++ compiler, suchas Borland and VC? Thanks
Take a look at this thread...
-
October 12th, 2003, 09:33 AM
#6
Well, your problem is called "name mangling". Every compiler in order to provide unique names to the various symbols (variables, classes, functions, enums etc.) within an object file, renames the symbol in a type-specific way, producing this way unique names for symbols of the same type. This allows you to use the name "foo" for both a method and a variable. These mangled names are used for resolving symbols during the linking phase - static or dynamic.
Attempting to export and then link / locate a symbol under the same compiler environment is no problem since the same mangling rules are used. In your case the Borland compiler is searching for the specified symbol using a different mangling scheme compared to this used during the library's compilation - performed by the VC compiler.
The link provided by Andreas provides various solutions to your problem. The .def file is a set of directives to the compiler in order to avoid using its internal mangling scheme and use the supplied name for certain symbols - making it possible to locate them through another compilation enviroment.
Regards,
--harizak
-
October 13th, 2003, 07:11 AM
#7
Originally posted by harizak
Well, your problem is called "name mangling". Every compiler in order to provide unique names to the various symbols (variables, classes, functions, enums etc.) within an object file, renames the symbol in a type-specific way, producing this way unique names for symbols of the same type. This allows you to use the name "foo" for both a method and a variable. These mangled names are used for resolving symbols during the linking phase - static or dynamic.
Attempting to export and then link / locate a symbol under the same compiler environment is no problem since the same mangling rules are used. In your case the Borland compiler is searching for the specified symbol using a different mangling scheme compared to this used during the library's compilation - performed by the VC compiler.
The link provided by Andreas provides various solutions to your problem. The .def file is a set of directives to the compiler in order to avoid using its internal mangling scheme and use the supplied name for certain symbols - making it possible to locate them through another compilation enviroment.
Regards,
--harizak
Thanks alot for reading through and spending times answering to my doubts. I really appreciate ur expanation and will try out the mentioned method . Have a Good Day!
BestRegards,
James Goh
-
October 15th, 2003, 05:12 AM
#8
nosplinters
How do I link the .lib with my main?
Thanks
-
October 15th, 2003, 05:29 AM
#9
In VC++ you can do it in 3 ways.
1. Using IDE, write the name of lib file in project setting link tab.
2. give the lib file name to linker when invoke compiler and linker at command prompt like
link glut32.lib, Opengl32.lib, glu32.lib MyProj.obj
3. Use pragma in you code like
Code:
#pragma comment (lib, "glut32.lib")
#pragma comment (lib, "Opengl32.lib")
#pragma comment (lib, "glu32.lib")
I prefer the 3rd option.
Hope it helps.
-
October 15th, 2003, 05:57 AM
#10
if I use option 3:
where is glut32.lib should be located (where should I put my lib)
about option 1:
what is IDE?
Where can I found the project properties (I'm using VC .NET)
about option 2:
give the lib file name to linker when invoke compiler and linker at command prompt like
How do I do that:
I mean how do I give the linker the file name, how do I invoke compiler/linker?
Thanks
-
October 15th, 2003, 02:49 PM
#11
an IDE is a package that includes a compiler, editor as well as anything else into 1 application.
VisualC++ is an IDE because it included a compiler AND editor.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|