Thread overview
[Issue 2776] New: pragma(lib, does not work when used in headers
Apr 01, 2009
d-bugmail
Apr 01, 2009
d-bugmail
Apr 26, 2009
d-bugmail
May 20, 2009
Jacob Carlborg
Apr 10, 2011
Andrej Mitrovic
Apr 10, 2011
Walter Bright
Apr 11, 2011
Jacob Carlborg
April 01, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2776

           Summary: pragma(lib, does not work when used in headers
           Product: D
           Version: 1.041
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: benoit@tionex.de


I tried to use the pragma(lib, ...) feature without success.

I build a lib called "org.eclipse.swt.win32.win32.x86.lib", the source contain several pragma declarations:

pragma(lib, "comctl32.lib"); // and more win32 libs
pragma(lib, "org.eclipse.swt.win32.win32.x86.lib"); // link to the lib itself

The module with those pragmas is always imported if the lib is used.

Now, when i compile a example using the lib and turn on verbose, dmd prints all
those lib lines
...
library   comctl32.lib
library   org.eclipse.swt.win32.win32.x86.lib
...

Later it prints the commands it passes to "link.exe", here the libs are
missing:
c:\Project\dwtinst\tango-0.99.8-bin-win32-dmd.1.041\bin\link.exe
"C:\Project\dwtinst\dwt-rcp\obj\SwtSnippet10","C:\Project\dwtinst\dwt-rcp\bin\SwtSnippet10.exe",,user32+kernel32/noi+C:\Project\dwtinst\dwt-rcp\lib\+tango-user-dmd.lib;

The result are all those symbols are missing.


-- 

April 01, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2776





------- Comment #1 from benoit@tionex.de  2009-04-01 08:23 -------
In DMD sources, the addition to the linker of the pragma(lib,..) happens in
attrib.c: PragmaDeclaration::toObjFile
which like the name implies while object file generation. This is not happening
for headers. So I think the solution should be to move this to the semantic()
method.


-- 

April 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2776





------- Comment #2 from larsivar@igesund.net  2009-04-26 11:12 -------
Just found this myself. This feature is much more useful when used for dependencies for libraries, than for building applications directly.

As long as the external library files are available, the application developer would only have to worry about linking the library he is using, not also those used by that library.


-- 

May 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2776





--- Comment #3 from Jacob Carlborg <doob@me.com>  2009-05-20 13:10:34 PDT ---
Created an attachment (id=377)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=377)
This patch should fix the problem

The patch is for dmd v1.045 and tested with Mac OS X.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2776


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-04-10 11:25:31 PDT ---
This issue still exists. Is anyone able to update this patch for latest versions of DMD (2.x included) and make a pull request on github?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2776


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2011-04-10 16:35:35 PDT ---
There are a couple problems with this patch.

1. It moves up to the semantic phase a call to set the include lib in an obj file. This is completely outside how obj files are written, and mucks up the separation of passes. It shouldn't work at all.

2. Lots of projects have a tendency to import lots of things. Sometimes none of it is referenced, sometimes only a minor declaration is referenced, sometimes the import is an unneeded private import of some other module. Demanding then that the referenced library exist and be linked in can cause its own frustrations and problems.


I don't know if there is a good solution to these problems. I don't think the patch is it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2776


Jacob Carlborg <doob@me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob@me.com


--- Comment #6 from Jacob Carlborg <doob@me.com> 2011-04-11 00:27:47 PDT ---
DSSS/rebuild/bu(il)d adds its on pragma, pragma(link, ...), which basically
works like pragma(lib, ...) with this patch. Except when linking a library with
pragma(link) you only specify the name of the library and then it automatically
adds the extension depending on the platform. It also prefix the library name
with "lib" on Posix systems.

Could we add a pragma(link) that behaves as the one in DSSS/rebuild/bu(il)d,
this won't break any existing code, if I'm not missing something?

I would also like something for frameworks on Mac OS X, see: http://d.puremagic.com/issues/show_bug.cgi?id=2968

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------