Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Using a VC++ .lib file from g++ (http://www.programmingforums.org/showthread.php?t=14318)

kurt Nov 1st, 2007 2:39 AM

Using a VC++ .lib file from g++
 
Hi.

If I have a .lib file which I think most likely compiled from Visual Studio, can I link that .lib in a project that uses g++/ld ?

I am using mingw32 compiler. I checked the manual -- doesn't seems to indicate any restrictions about this.

Is mingw32 a good choice to begin with?

I know the contents and functions within that .lib. What I am trying to do is building it in a non-visual-studio environment.

Thanks.

Ancient Dragon Nov 1st, 2007 7:43 AM

Re: Using a VC++ .lib file from g++
 
c++ libraries created with Microsoft compilers probably can not be used with other compilers because of the non-standard way of mangling symbol names, and non-standard format of libraries. I'd suggest you get the source code of the library and compile it with your g++ compiler.

WaltP Nov 2nd, 2007 9:09 PM

Re: Using a VC++ .lib file from g++
 
Ancient Dragon is right. Trying to use an M$ library with g++ is like trying to use a VW transmission in a Ford truck. They don't play well together.

Jimbo Nov 2nd, 2007 10:11 PM

Re: Using a VC++ .lib file from g++
 
Not directly related, but though I'd mention that this doesn't happen in C, thanks to a lack of name mangling. Unfortunately, if your .lib is already compiled and/or the library code isn't in C, then you'll still have a problem...

lectricpharaoh Nov 3rd, 2007 1:06 AM

Re: Using a VC++ .lib file from g++
 
Quote:

Originally Posted by Jimbo
Not directly related, but though I'd mention that this doesn't happen in C, thanks to a lack of name mangling.

Well, it kind of does. Even in the absence of C++ name-mangling to encode parameter information, the name of a symbol in source was not necessarily the same as its object module counterpart. As an example, some compilers prepend a leading underscore to non-local symbols, whereas others don't. This is aside from all the other differences between object file formats.

Ancient Dragon Nov 3rd, 2007 8:22 AM

Re: Using a VC++ .lib file from g++
 
Quote:

Originally Posted by lectricpharaoh (Post 136225)
. As an example, some compilers prepend a leading underscore to non-local symbols, whereas others don't. .

yes I've seen that before two between Microsoft and Borland compilers. Microsoft puts the '_' in front of the symbol name while Borland compilers put it after the name.

DaWei Nov 3rd, 2007 9:41 AM

Re: Using a VC++ .lib file from g++
 
Modification of names in C is more commonly called decoration and involves more than underscores. It provides information about the calling convention (who cleans the stack frame, for one).

C++ (and other languages) uses mangling, since it has to provide copious amounts of information (for overloading and other purposes). Each implementation has to convey more information than a simple description of parameters; for instance, interrupts (some due to error conditions) in one chip family may do entirely different things to the stack frame than interrupts from a different chip family. Layout of structs may be constrained by physical memory implementations. All this can make it very difficult to employ a standardized scheme.

Why compilers that deal with the same architecture/hardware use differing schemes is anyone's guess.

WaltP Nov 3rd, 2007 1:41 PM

Re: Using a VC++ .lib file from g++
 
Quote:

Originally Posted by DaWei (Post 136227)
Why compilers that deal with the same architecture/hardware use differing schemes is anyone's guess.

That's easy...
Microsoft: "We don't want none o' that Borland sh** being used with our compilers!"

grumpy Nov 6th, 2007 1:30 AM

Re: Using a VC++ .lib file from g++
 
Quote:

Originally Posted by DaWei (Post 136227)
Why compilers that deal with the same architecture/hardware use differing schemes is anyone's guess.

That's easy: vendors looking for an edge over competitors. If vendor X can lock a developer into using features that are not supported by (or incompatible with) vendor Y, developers are more likely to stick with vendor X through upgrades, rather than buying a product from vendor Y. Since support of multiple compilers or development environments takes effort, a lot of developers will take the easy path and only use one vendor's compiler.


All times are GMT -5. The time now is 3:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC