NO

Author Topic: linking with libraries created using MSVC  (Read 4968 times)

borgfan

  • Guest
linking with libraries created using MSVC
« on: August 22, 2005, 07:40:25 PM »
I'm not sure I understand the nuances of linking to libraries built using MS VC (in C - not C++).  My experiments show that if I compile a library in MSVC using the Zl switch (remove default library information), then I can link ok, otherwise I get error messages when linking, for example cannot find libc.

Am I on the right track, or missing some tricks. Am I likely to have problems linking to 3rd party libraries where I don't have the source?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
linking with libraries created using MSVC
« Reply #1 on: August 22, 2005, 08:05:53 PM »
Both the Microsoft C(++) compiler and Pelles C compiler will by default embed linker directives in object files: /defaultlib:name.lib is probably the most common. The actual library name can change depending on debug settings, multi-threading settings, and so on. This is to help produce a correct executable - maybe not so good to compile for multi-threading and link for single threading, for example.

If you want to override the default, you can either make sure the information is never written to object files (/Zl compiler option) or tell the linker to ignore the embedded /defaultlib info (/NODEFAULTLIB linker option).

(You can use PODUMP /directives name.obj (Pelles C) or DUMPBIN /directives name.obj (MSVC) to look at any embedded directives in an object file - a library file will work too, I think.)

Hope this made some sense...

Pelle
/Pelle

borgfan

  • Guest
linking with libraries created using MSVC
« Reply #2 on: August 22, 2005, 09:22:05 PM »
ok, thanks - that makes sense.  I didnt spot that the linker option 'iignore  standard places' set /nodefaultlib.  

On a related subject I have a problem resolving some symbols from a MSVC library, examples are:
__allmul  and __aulldiv

I suspect they are used in MSVC for big number maths, is there a way of resolving these in pellesc?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
linking with libraries created using MSVC
« Reply #3 on: August 22, 2005, 10:36:44 PM »
Quote from: "borgfan"
On a related subject I have a problem resolving some symbols from a MSVC library, examples are:
__allmul  and __aulldiv

I suspect they are used in MSVC for big number maths, is there a way of resolving these in pellesc?

Yes, they should be for '__int64' integers.

I got very similar functions, but the names are different (without the 'a' in your example). No easy way to map between different names (an assembler can be used, but that's a long story), so maybe a simple translation layer(?):

Code: [Select]

extern __int64 __stdcall __llmul(__int64, __int64);
extern __int64 __stdcall __ulldiv(__int64, __int64);

__int64 __stdcall __allmul(__int64 a, __int64 b)
{
    return __llmul(a, b);
}

__int64 __stdcall __aulldiv(__int64 a, __int64 b)
{
    return __ulldiv(a, b);
}


(Untested, and all that...)

EDIT: I forgot, use the Pelles C compiler with the /Gm option - the names are undecorated, but the call behaves like a __stdcall function...
Pelle
/Pelle