Page 1 of 1

About #Pragma Library

Posted: Thu May 26, 2022 12:27 am
by Victorio
Hi,
Can anyone explain to me what is the difference between using e.g. #Pragma Library ("Ascom10.LIB") in a PRG file, or in an XPJ project file as COMPILE_FLAGS = ..... /rAscom10.LIB,
or why, in fact, only these LIBs are so called in some PRGs?
E.g. DCLIPX.LIB, ASCOM10.LIB, Adac20b.LIB, XppUI2.LIB, but the system will find the others itself.
Adac20b.LIB for example I have a note that it needs DacPagedDataStore () - I think it was some module from Jimmy


Viktor

Re: About #Pragma Library

Posted: Thu May 26, 2022 3:42 am
by Tom
Hi, Viktor.

The #pragma-directive switches a compiler switch only for that PRG. This allows to activate or deactivate compiler setting like for the usage of a LIB/DLL only for a single DLL. The #pragma library-directive is used to link a library/DLL only to one PRG instead of having it in/available for all sources. If you just have one PRG, it doesn't make any difference. If you have tons of PRGs and maybe use the Chilkat-library only in one of those, maybe since all JSON- or SFTP-stuff is located there, it may reduce ressources if you use #pragma library there. But you have to place the #pragma lib-directive everywhere you directly use functions from that library!

#pragma knows other switches, like switching on/off the compilation with line numbers. Just take a look at the docs.

Re: About #Pragma Library

Posted: Fri May 27, 2022 1:44 am
by Victorio
Hi Tom,

Thanks for the explanation. If I understand correctly, it is only because when compiling if I have a lot of PRGs (in my case more than 100), this LIB (eg Adac20b.lib) is used in the compilation process only when the PRG, which of it function needs?
So that it does not unnecessarily burden the compiler's memory with other PRGs?
Or does it affect the generated EXE itself, which will then require more resources to run?

Viktor

Re: About #Pragma Library

Posted: Fri May 27, 2022 1:00 pm
by rdonnay
I have never heard about #pragma Library requiring more resources to run.

This is simply a linker directive and should have the same effect as including a .LIB reference in an .XPJ file.

Look at the below code for Test.Prg / Text.Exe :

Code: Select all

#Pragma Library("dclipx.lib")

FUNCTION Main()

? dc_versionexpress()
? 'Hello world'
wait

RETURN nil
If I compile and link this to TEST.EXE, I can see which DLLs are loaded at runtime by running Chk4dll test.exe.
I will get the following response:

DCLIPX.dll -> c:\expd20\bin20\DCLIPX.dll can be loaded.
XPPRT1.dll -> C:\Program Files (x86)\Alaska Software\xpp20\lib\XPPRT1.dll can be loaded.
xppsys.dll -> C:\Program Files (x86)\Alaska Software\xpp20\lib\xppsys.dll can be loaded.
XPPDBGC.dll -> C:\Program Files (x86)\Alaska Software\xpp20\lib\XPPDBGC.dll can be loaded.

However, if I comment out the dc_versionexpress() call, so there is nothing calling anything in dclipx.dll, but still leave the #Pragma Library("dclipx.lib") in the code, the dclipx.dll will never be loaded. Chk4dll test.exe will return the following response in that case:

XPPRT1.dll -> C:\Program Files (x86)\Alaska Software\xpp20\lib\XPPRT1.dll can be loaded.
xppsys.dll -> C:\Program Files (x86)\Alaska Software\xpp20\lib\xppsys.dll can be loaded.
XPPDBGC.dll -> C:\Program Files (x86)\Alaska Software\xpp20\lib\XPPDBGC.dll can be loaded.

The DLLs that are loaded at runtime are determined by the linker. It gets the list of exported symbols from the .LIB file of the same name as the .DLL file. It also gets the list of called symbols from all the .OBJ files. The only way that a DLL gets loaded is If there is at least 1 reference to a function name that exists the .LIB file that is also in one of your .OBJ files.

#Pragma Library in a .PRG file is a handy reference to use if you are sending some code to another person to link into their application, but don't want to create a .XPJ file, because they probably already have their own .XPJ file.

Re: About #Pragma Library

Posted: Mon May 30, 2022 6:52 am
by Victorio
Hi Roger,

Thank you very much for the explanation. I understand that now.
Have a nice day.

Viktor