Hi
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?
BTW: this causes a compiler error: const barlib = 'bar'; function foo : integer; external barlib name 'foo';
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
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, c.f. <http://developer.apple.com/releasenotes/DeveloperTools/ TwoLevelNamespaces.html> and <http://developer.apple.com/documentation/Porting/Conceptual/ PortingUnix/compiling/chapter_4_section_6.html>.
Regards,
Adriaan van Os
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/
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 think we've discussed it before. Basically, I agree. However, such a feature has to be implemented on the linker-call level, i.e., via automake or GP (or hand-written Makefiles which is the individual author's responsibility). I have no plans to do any further work on automake. I'd like to do it in GP when I get to it. But it isn't exactly trivial, also due to Delphi's complex syntax here:
BTW: this causes a compiler error: const barlib = 'bar'; function foo : integer; external barlib name 'foo';
Supporting expressions instead of string constant here is a bit tricky. It might be feasible for the linker name. With the library name with GP it will get even harder. I might look at it sometime, but it's not really high priority to me ATM. (If you need something similar, you can probably use macros which should work here.)
Frank