On 4 Feb 2006 at 11:49, Adriaan van Os wrote:
Prof A Olowofoyeku (The African Chief) wrote:
If you have something like this: function foo : integer; external 'bar' name 'foo'; you get a warning that the library name in 'external' is ignored. Is it possible, instead of ignoring the library name, to generate an implicit call to link it? For example, the example above would resolve to an implicit '-lbar' (i.e., it would be the equivalent of '{$l bar}').
Is this feasible, and is there any reason why it would be a bad idea?
I don't think the purpose of the construct "external 'bar' name 'foo'" should be to automatically link in library bar, but rather to record that the function foo is located in library bar, to be more precise, to indicate that with the external declaration the function foo in the library bar is meant and not an eventual function of the same name in another library,
[...]
Indeed. But that is just one part of it. This feature, I believe, is a Delphi compatibility feature, and in Delphi, it is also equivalent to a directive to load the external library at program startup. This is from the Delphi 7 help file:
"The simplest way to import a procedure or function is to declare it using the external directive. For example,
On Windows: procedure DoSomething; external 'MYLIB.DLL';
On Linux: procedure DoSomething; external 'mylib.so';
If you include this declaration in a program, MYLIB.DLL (Windows) or mylib.so (Linux) is loaded once, when the program starts. Throughout execution of the program, the identifier DoSomething always refers to the same entry point in the same shared library."
I don't know how/if GPC does this, but I would have thought that linking in the library automatically would be one way of achieving it.
Under Mingw/Cygwin, '-lbar' would look for 'libbar.dll.a' and 'libbar.a' in that order (I think).
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/