Link .lib only without the dll?

Just starting out? Need help? Post your questions and find answers here.
pamen
Enthusiast
Enthusiast
Posts: 193
Joined: Sat Dec 31, 2022 12:24 pm
Location: Cyprus
Contact:

Link .lib only without the dll?

Post by pamen »

Hi,
confused newbie question (Windows).
I can import functions from a system libs or other lib, if present on the system.
Now - I do have a full C++ source of a massive library but want to use only certain classes (dll is 16MB, used functions are juts few classes, if I include sources and make an app in a C++ app - it results in a 50KB executable with no dependencies). I cannot split easily the useful and not useful code by hand - 60K lines referencing lots of common functions is hard to digest and clean up.

Is there a way to use .lib or obj files produced by C++ (VS in this case) with Purebasic so, that the linker takes what is needed and no DLL is needed?
Using C backend? Or something more straight forward?

Assume I have this in the lib, declared it correctly and it is all I need:

Code: Select all

Import "mylib.lib"  ; or ImportC depending on what is correct for 32/64 particular lib.
  Dosomething.l (num1.l, num2.l, num3.l, num4.l) As "_Anything@16FunctionX"  
EndImport
Now, this is simple and nice, works. But if I compile - I still need the 16 megs DLL to execute the Dosomething().
S.T.V.B.E.E.V.
infratec
Always Here
Always Here
Posts: 7706
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Link .lib only without the dll?

Post by infratec »

A lib is not a lib :wink:

In one case it is only a description of the exported functions of a dynamic loading lib.
In the other case it is a static lib.

If you have a static lib, than you don't need a dll file beside.
Else you need the dll file.
pamen
Enthusiast
Enthusiast
Posts: 193
Joined: Sat Dec 31, 2022 12:24 pm
Location: Cyprus
Contact:

Re: Link .lib only without the dll?

Post by pamen »

Thanks, I have a real static lib and, if needed obj files.
A test with simple windows 64 C app using the lib file compiles the code into a working exe. size increases correctly by some 90-100KB. No dll required -runs for a an empty directory with no dll in the Path.

but it is a mystery to me in PureBasic: just declaring imports does not result in PB compiler including it in the executable (the same static lib) and cries for a DLL.

Should the import declaration be different or do I need a set of object files or some linker switches?
S.T.V.B.E.E.V.
User avatar
idle
Always Here
Always Here
Posts: 6101
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Link .lib only without the dll?

Post by idle »

The imports are exactly the same between a static lib and an import lib to a dll. But I doubt you'll be able to link against a c++ static lib without loads of unresolved symbols as pb still uses an older crt lib which isn't compatible with the ucrt. You will need the dll
pamen
Enthusiast
Enthusiast
Posts: 193
Joined: Sat Dec 31, 2022 12:24 pm
Location: Cyprus
Contact:

Re: Link .lib only without the dll?

Post by pamen »

Correct, thanks Idle
the lib is fine, my bad (used the wrong lib) but I get a lot of MSVCRT unresolved dependencies (no other dependencies though)
Can I just replace msvcrt.lib with any other up to date one from the correct compiler (the C++ uses only MSVCRT and windows native calls, so only one msvcrt.lib for VS 170 is missing) ?

Or even better (or worse) - somehow force VS2022 to compile msvcrt for the correct VS platform into the lib first?
I couldn't figure the latter out - static build, uses /MD switch, use MFC as a static lib - no luck...
S.T.V.B.E.E.V.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Link .lib only without the dll?

Post by Kuron »

pamen wrote: Sat Sep 23, 2023 1:01 pm(dll is 16MB
:shock:
Best wishes to the PB community. Thank you for the memories. ♥️
pamen
Enthusiast
Enthusiast
Posts: 193
Joined: Sat Dec 31, 2022 12:24 pm
Location: Cyprus
Contact:

Re: Link .lib only without the dll?

Post by pamen »

Exactly.
If the functionality used from a lib is only a fraction of the whole shebang and my whole app is 3.5 MB with all needed inside - 16MB really aches.
If that was my job's software with 240MB of DLLs and .net and 40MB executable - no problem, but PureBasic should be pure :-(

So - any great idea to resolve msvcrt dependencies with polink?
S.T.V.B.E.E.V.
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: Link .lib only without the dll?

Post by Mijikai »

You can try a naked:

Code: Select all

Import "msvcrt.lib"
EndImport
pamen
Enthusiast
Enthusiast
Posts: 193
Joined: Sat Dec 31, 2022 12:24 pm
Location: Cyprus
Contact:

Re: Link .lib only without the dll?

Post by pamen »

Thanks Mijikai I did, the same unresolved dependencies,
so possibly I would have to get hold of the polink log and create includes for all functions used... then run again and again, until I have included all dependencies one by one??? If that would be a solution at all.

Same unresolved functioons, like CObject, afx_ ...
S.T.V.B.E.E.V.
User avatar
idle
Always Here
Always Here
Posts: 6101
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Link .lib only without the dll?

Post by idle »

Chi has a solution it replaces the msvcrt and crt and probably a couple more in the libs folder, it's switchable but I haven't had a need to try it yet, try a search or look through Chi's posts.
Olli
Addict
Addict
Posts: 1272
Joined: Wed May 27, 2020 12:26 pm

Re: Link .lib only without the dll?

Post by Olli »

And instead of swimm in the hell of dependancies for, I repeat your sentences, a fraction of functions, maybe you could check if the features you need are controlable from pureBasic, asking the technical questions in the coding questions...

It is just a suggestion (not humour).
pamen
Enthusiast
Enthusiast
Posts: 193
Joined: Sat Dec 31, 2022 12:24 pm
Location: Cyprus
Contact:

Re: Link .lib only without the dll?

Post by pamen »

Thank you Olli and Idle (are you always coming in duets?)

All the matters in question are all fully controllable in PureBasic - at the end it boils down to WinAPI or another OS system calls anyway.
I tried a part of it - yes, would work.
But having those functions with only around 50,000 lines of C++ code which is solid, written and improved over 10 years and tested by few hundred people - well it would take at least few months to make the same with the same quality and bug free, wouldn't it?
At least for a slow coder like me - since starting with PB last December I only wrote 30,000 working lines of code and the rest is trash.
So fighting with dependencies may be a bit shorter for a beginner.
I will check Chi's solution, then meditate on my own Chi and finally follow the path given to me by this wondrous forum using weighted average of all these well-meaning opinions.
S.T.V.B.E.E.V.
Olli
Addict
Addict
Posts: 1272
Joined: Wed May 27, 2020 12:26 pm

Re: Link .lib only without the dll?

Post by Olli »

pamen wrote:At least for a slow coder like me
:lol: I am not sure you are the slowest !

So, you say you are on a system as strong as there are hundreds people which have tested it during one decade.

It is okay, but your coding speedness, as you measure it, is certainly in opposition of your imagination. If you think you can easily imagine and easily apply any new concepts through this c++ program, sure you have to dig to get the right and clever links between pureBasic and c++.

But if you see, you are limited by a complex program you cannot simplify, to apply what your experience offers to you, in this way, maybe, step by step, you should build your own library.

A c++ dependancy, it often is for a specific domain (network, interface, etc...). When a c++ dependancy shut a pureBasic feature down, it is not sure this dependancy has passed over all the technical tests.

Now, you said all the windows theme is modified automatically thank to such a system. That is sure, such a desktop change, is a big question. Personally, I cannot answer to this question : I am focusing on the native features of pureBasic and on what we can do onto one software. But, there are lots of people here who share their knowledges.

We can say, here, we do not test one software specifically, deleting all the subjects, which are out of interest. But we test any parts of code (in addition of the technical questions). We test ouself, and a question becomes the main rule of a small contest. And if any interests come to conflicts, it is frozen (locked), not deleted...

The lonely subjects which are deleted here, these are bots !
Last edited by Olli on Mon Sep 25, 2023 10:29 pm, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 6101
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Link .lib only without the dll?

Post by idle »

here's the link to the Chi's tool
viewtopic.php?t=81177
Olli
Addict
Addict
Posts: 1272
Joined: Wed May 27, 2020 12:26 pm

Re: Link .lib only without the dll?

Post by Olli »

idle wrote: Mon Sep 25, 2023 10:26 pm here's the link to the Chi's tool
viewtopic.php?t=81177
@idle, when I read you so often, in a so short period, that indicates to me, it is the hour for me to sleep.
Post Reply