View previous topic :: View next topic |
Author |
Message |
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Thu Dec 14, 2006 1:27 pm Post subject: pragma(link) on Linux |
|
|
Hi there!
I'm using bud to compile a project that needs to import a library ( libpq.a ). In the module that needs this library, I have the following code:
Code: |
version(build) {
pragma(link, libpq);
}
|
When I run build -op -full -test myApp.d, build doesn't include libpq.a in the linking. I have also tried:
Code: |
version(build) {
pragma(link, "libpq.a");
}
version(build) {
pragma(link, libpq.a);
}
|
The libpq.a file resides both in the directory of the module that links it and /usr/lib.
Any help would be greatly appreciated ,
~Morgan McDermott
[/code] |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Thu Dec 14, 2006 2:23 pm Post subject: Re: pragma(link) on Linux |
|
|
mmcdermo wrote: | Hi there!
I'm using bud to compile a project that needs to import a library ( libpq.a ). In the module that needs this library, I have the following code:
Code: |
version(build) {
pragma(link, libpq);
}
|
When I run build -op -full -test myApp.d, build doesn't include libpq.a in the linking. I have also tried:
|
Do you mean that Bud doesn't place 'libpq' on the command line or that the linker doesn't find the library?
Also, doesn't Linux have the quirk in which you all libraries begin with "lib" and so you must not include "lib" as the linker prefixes that for you. If so, why not try "pragma(link, pq);" ? _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Thu Dec 14, 2006 3:07 pm Post subject: |
|
|
Bud simply isn't passing libpq.a to the linker (observable with -test output). Changing libpq to pq doesn't do anything, unfortunately.
For more clarification, here's a sample of the -test output:
Code: |
Command: /path/to/dmd -c -version=Posix -op -I"path/to/phobos" -I"/other/relevant/paths..." myApp.d myimport1.d myimport2.d /path/to/phobos/stdimport1.d /path/to/phobos/stdimport2.std
Command: /path/to/gcc myApp.o myimport1.o myimport2.o /path/to/phobos/stdimport1.o /path/to/phobos/stdimport2.o -o myApp -lc -lphobos -lpthread -lm
|
I think a good place to start here might be asking, under what circumstances does bud not pass libraries to the linker?
Thanks for your time,
~Morgan McDermott |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Fri Dec 15, 2006 8:32 pm Post subject: |
|
|
I've been playing around with Bud's source, but I'm having a hard time finding the code that processes pragma(links) [or just pragmas], and I have only a faint idea of how this is aggregated into the final linker command. Could you give me a brief overview of how bud processes a pragma(link) and how it eventually gets included into the linker cmd so that I can do some testing?
Thanks for your time,
~Morgan McDermott |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Fri Dec 15, 2006 10:07 pm Post subject: |
|
|
Quick-hack-solution found::
In source.d:
Code: |
On line 1234:
Replace: if (lCurrentToken == "link")
With: if (lCurrentToken == "link" || pFileText[pPos..pPos+4] == "link")
On line 1273:
Replace: if (AddLink != null) {
With: if (AddLink != null && lPragmaId.dup[0..4] != "link") {
|
Without this hack, the if statement's condition was never true. The hack on line 1273 fixes a bug that this hack causes [ You end up bud adding link.a to the list ]. |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Sat Dec 16, 2006 8:27 am Post subject: |
|
|
mmcdermo wrote: | Quick-hack-solution found::
In source.d:
Code: |
On line 1234:
Replace: if (lCurrentToken == "link")
With: if (lCurrentToken == "link" || pFileText[pPos..pPos+4] == "link")
On line 1273:
Replace: if (AddLink != null) {
With: if (AddLink != null && lPragmaId.dup[0..4] != "link") {
|
Without this hack, the if statement's condition was never true. The hack on line 1273 fixes a bug that this hack causes [ You end up bud adding link.a to the list ]. |
This hack is not valid. When I run Bud with using this pragma I'm getting it to work okay. The current token is "link" when I run it.
Run it again with the -V -test switches and post the output here so I can see a bit more of what it is doing. _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Sun Dec 17, 2006 11:15 am Post subject: |
|
|
Calling build with the -V switch doesn't seem to do anything for me.. I get no additional output. I've also made sure that this wasn't the product of a modification to build - the vanilla source does the same thing. Am I missing something here? |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Dec 18, 2006 12:19 am Post subject: |
|
|
mmcdermo wrote: | Calling build with the -V switch doesn't seem to do anything for me.. I get no additional output. I've also made sure that this wasn't the product of a modification to build - the vanilla source does the same thing. Am I missing something here? |
In order to get verbose output from Bud, you need to 'make' it with the switch "-version=BuildVerbose". I'm sorry I didn't mention this earlier as I do it for the Windows releases but I don't release Unix binaries for Bud. I mentioned it in the change log for v3.00 but I really should add a section in the docs about how to build Bud. _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Mon Dec 18, 2006 10:24 am Post subject: |
|
|
Thanks for the explanation . Here's my output when I perform
Code: |
build -test -full -op -V
|
with
Code: |
import std.stdio;
version(build) {
pragma(link, pq);
}
void main() {
}
|
*** build v3.04 (build 2515)***
Default target is 'btest'
Current Dir '/home/mmcdermo/'
Compiler installed in /usr/local/bin/
Active Version: 'DigitalMars'
Active Version: 'D_InlineAsm'
Active Version: 'build'
Active Version: 'BuildVerbose'
Active Version: 'X86'
Active Version: 'Posix'
Active Version: 'LittleEndian'
Active Version: 'linux'
Reading from config: /etc/dmd.conf
Line 1:
Line 2: [Environment]
Line 3:
Line 4: DFLAGS=-I/home/mmcdermo/dmdincludes/
added root from config file /home/mmcdermo/dmdincludes/
linker path '/usr/lib/ccache/'
linker is 'gcc'
librarian path '/usr/bin/'
librarian is 'ar'
file->module btest.d => btest
Updating btest.d dependants time from 1166375337 to 1166459110
Time 1166375337 for source btest.d
Time 1166459110 for object btest.o
Scanning btest.d
module->file std.stdio => dmdincludes/std/stdio.d
file->module dmdincludes/std/stdio.d => dmdincludes.std.stdio
Updating dmdincludes/std/stdio.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/stdio.d
Time 1166459110 for object dmdincludes/std/stdio.o
Scanning dmdincludes/std/stdio.d
Module name set to 'std.stdio'
module->file std.c.stdio => dmdincludes/std/c/stdio.d
module->file std.format => dmdincludes/std/format.d
module->file std.utf => dmdincludes/std/utf.d
file->module dmdincludes/std/c/stdio.d => dmdincludes.std.c.stdio
Updating dmdincludes/std/c/stdio.d dependants time from 1162449242 to 1166459110
Time 1162449242 for source dmdincludes/std/c/stdio.d
Time 1166459110 for object dmdincludes/std/c/stdio.o
Scanning dmdincludes/std/c/stdio.d
Module name set to 'std.c.stdio'
module->file std.c.stddef => dmdincludes/std/c/stddef.d
module->file std.c.stdarg => dmdincludes/std/c/stdarg.d
file->module dmdincludes/std/c/stddef.d => dmdincludes.std.c.stddef
Updating dmdincludes/std/c/stddef.d dependants time from 1162449242 to 1166459110
Time 1162449242 for source dmdincludes/std/c/stddef.d
Time 1166459110 for object dmdincludes/std/c/stddef.o
Scanning dmdincludes/std/c/stddef.d
Module name set to 'std.c.stddef'
file->module dmdincludes/std/c/stdarg.d => dmdincludes.std.c.stdarg
Updating dmdincludes/std/c/stdarg.d dependants time from 1162449242 to 1166459110
Time 1162449242 for source dmdincludes/std/c/stdarg.d
Time 1166459110 for object dmdincludes/std/c/stdarg.o
Scanning dmdincludes/std/c/stdarg.d
Module name set to 'std.c.stdarg'
file->module dmdincludes/std/format.d => dmdincludes.std.format
Updating dmdincludes/std/format.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/format.d
Time 1166459110 for object dmdincludes/std/format.o
Scanning dmdincludes/std/format.d
Module name set to 'std.format'
module->file std.stdarg => dmdincludes/std/stdarg.d
module->file std.utf => dmdincludes/std/utf.d
module->file std.c.stdlib => dmdincludes/std/c/stdlib.d
module->file std.c.string => dmdincludes/std/c/string.d
module->file std.string => dmdincludes/std/string.d
file->module dmdincludes/std/stdarg.d => dmdincludes.std.stdarg
Updating dmdincludes/std/stdarg.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/stdarg.d
Time 1166459110 for object dmdincludes/std/stdarg.o
Scanning dmdincludes/std/stdarg.d
Module name set to 'std.stdarg'
file->module dmdincludes/std/utf.d => dmdincludes.std.utf
Updating dmdincludes/std/utf.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/utf.d
Time 1166459110 for object dmdincludes/std/utf.o
Scanning dmdincludes/std/utf.d
Module name set to 'std.utf'
module->file std.stdio => dmdincludes/std/stdio.d
file->module dmdincludes/std/c/stdlib.d => dmdincludes.std.c.stdlib
Updating dmdincludes/std/c/stdlib.d dependants time from 1162449242 to 1166459110
Time 1162449242 for source dmdincludes/std/c/stdlib.d
Time 1166459110 for object dmdincludes/std/c/stdlib.o
Scanning dmdincludes/std/c/stdlib.d
Module name set to 'std.c.stdlib'
module->file std.c.stddef => dmdincludes/std/c/stddef.d
file->module dmdincludes/std/c/string.d => dmdincludes.std.c.string
Updating dmdincludes/std/c/string.d dependants time from 1162449242 to 1166459110
Time 1162449242 for source dmdincludes/std/c/string.d
Time 1166459110 for object dmdincludes/std/c/string.o
Scanning dmdincludes/std/c/string.d
Module name set to 'std.c.string'
file->module dmdincludes/std/string.d => dmdincludes.std.string
Updating dmdincludes/std/string.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/string.d
Time 1166459110 for object dmdincludes/std/string.o
Scanning dmdincludes/std/string.d
Module name set to 'std.string'
module->file std.stdio => dmdincludes/std/stdio.d
module->file std.c.stdio => dmdincludes/std/c/stdio.d
module->file std.c.stdlib => dmdincludes/std/c/stdlib.d
module->file std.c.string => dmdincludes/std/c/string.d
module->file std.utf => dmdincludes/std/utf.d
module->file std.uni => dmdincludes/std/uni.d
module->file std.array => dmdincludes/std/array.d
module->file std.format => dmdincludes/std/format.d
module->file std.ctype => dmdincludes/std/ctype.d
module->file std.stdarg => dmdincludes/std/stdarg.d
file->module dmdincludes/std/uni.d => dmdincludes.std.uni
Updating dmdincludes/std/uni.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/uni.d
Time 1166459110 for object dmdincludes/std/uni.o
Scanning dmdincludes/std/uni.d
Module name set to 'std.uni'
file->module dmdincludes/std/array.d => dmdincludes.std.array
Updating dmdincludes/std/array.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/array.d
Time 1166459110 for object dmdincludes/std/array.o
Scanning dmdincludes/std/array.d
Module name set to 'std.array'
module->file std.c.stdio => dmdincludes/std/c/stdio.d
file->module dmdincludes/std/ctype.d => dmdincludes.std.ctype
Updating dmdincludes/std/ctype.d dependants time from 1162449240 to 1166459110
Time 1162449240 for source dmdincludes/std/ctype.d
Time 1166459110 for object dmdincludes/std/ctype.o
Scanning dmdincludes/std/ctype.d
Module name set to 'std.ctype'
source file[0] btest.d
Newer time: from not recorded to 1166459110
source file[1] dmdincludes/std/stdio.d
source file[2] dmdincludes/std/c/stdio.d
source file[3] dmdincludes/std/c/stddef.d
source file[4] dmdincludes/std/c/stdarg.d
source file[5] dmdincludes/std/format.d
source file[6] dmdincludes/std/stdarg.d
source file[7] dmdincludes/std/utf.d
source file[8] dmdincludes/std/c/stdlib.d
source file[9] dmdincludes/std/c/string.d
source file[10] dmdincludes/std/string.d
source file[11] dmdincludes/std/uni.d
source file[12] dmdincludes/std/array.d
source file[13] dmdincludes/std/ctype.d
link file[0] pq.a not recorded
Building target '/home/mmcdermo/btest'
Time 1166459111 for btest (target)
Time 1166459110 (most recent)
Compiling with ..........
-version=Posix -op -I"/home/mmcdermo/dmdincludes/" -I"/home/mmcdermo/" -I"/home/mmcdermo/dmdincludes/std/" -I"/home/mmcdermo/dmdincludes/std/c/" btest.d dmdincludes/std/stdio.d dmdincludes/std/c/stdio.d dmdincludes/std/c/stddef.d dmdincludes/std/c/stdarg.d dmdincludes/std/format.d dmdincludes/std/stdarg.d dmdincludes/std/utf.d dmdincludes/std/c/stdlib.d dmdincludes/std/c/string.d dmdincludes/std/string.d dmdincludes/std/uni.d dmdincludes/std/array.d dmdincludes/std/ctype.d
Command: '/usr/local/bin/dmd -c -version=Posix -op -I"/home/mmcdermo/dmdincludes/" -I"/home/mmcdermo/" -I"/home/mmcdermo/dmdincludes/std/" -I"/home/mmcdermo/dmdincludes/std/c/" btest.d dmdincludes/std/stdio.d dmdincludes/std/c/stdio.d dmdincludes/std/c/stddef.d dmdincludes/std/c/stdarg.d dmdincludes/std/format.d dmdincludes/std/stdarg.d dmdincludes/std/utf.d dmdincludes/std/c/stdlib.d dmdincludes/std/c/string.d dmdincludes/std/string.d dmdincludes/std/uni.d dmdincludes/std/array.d dmdincludes/std/ctype.d '
Linking with ..........
btest.o dmdincludes/std/stdio.o dmdincludes/std/c/stdio.o dmdincludes/std/c/stddef.o dmdincludes/std/c/stdarg.o dmdincludes/std/format.o dmdincludes/std/stdarg.o dmdincludes/std/utf.o dmdincludes/std/c/stdlib.o dmdincludes/std/c/string.o dmdincludes/std/string.o dmdincludes/std/uni.o dmdincludes/std/array.o dmdincludes/std/ctype.o -o btest -lc -lphobos -lpthread -lm -lpq
Command: '/usr/lib/ccache/gcc btest.o dmdincludes/std/stdio.o dmdincludes/std/c/stdio.o dmdincludes/std/c/stddef.o dmdincludes/std/c/stdarg.o dmdincludes/std/format.o dmdincludes/std/stdarg.o dmdincludes/std/utf.o dmdincludes/std/c/stdlib.o dmdincludes/std/c/string.o dmdincludes/std/string.o dmdincludes/std/uni.o dmdincludes/std/array.o dmdincludes/std/ctype.o -o btest -lc -lphobos -lpthread -lm -lpq'
build args: ...............
[ 0]: -version=Posix (COMPILER)
[ 1]: -op (COMPILER)
[ 2]: -test
[ 3]: -full
[ 4]: -V
[ 5]: -I/home/mmcdermo/dmdincludes/ (DFLAG)
compiler args: ................
[ 0]: -version=Posix
[ 1]: -op
[ 2]: -I"/home/mmcdermo/dmdincludes/"
[ 3]: -I"/home/mmcdermo/"
[ 4]: -I"/home/mmcdermo/dmdincludes/std/"
[ 5]: -I"/home/mmcdermo/dmdincludes/std/c/"
command line files: ...............
[ 0]: btest.d
source files: ...............
[ 0]: btest.d
[ 1]: dmdincludes/std/stdio.d
[ 2]: dmdincludes/std/c/stdio.d
[ 3]: dmdincludes/std/c/stddef.d
[ 4]: dmdincludes/std/c/stdarg.d
[ 5]: dmdincludes/std/format.d
[ 6]: dmdincludes/std/stdarg.d
[ 7]: dmdincludes/std/utf.d
[ 8]: dmdincludes/std/c/stdlib.d
[ 9]: dmdincludes/std/c/string.d
[10]: dmdincludes/std/string.d
[11]: dmdincludes/std/uni.d
[12]: dmdincludes/std/array.d
[13]: dmdincludes/std/ctype.d
link files: ...............
[ 0]: pq.a
import roots: .................
[ 0]: /home/mmcdermo/dmdincludes/
[ 1]: /home/mmcdermo/
[ 2]: /home/mmcdermo/dmdincludes/std/
[ 3]: /home/mmcdermo/dmdincludes/std/c/
ignored packages: .................
[ 0]: phobos |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Dec 18, 2006 6:51 pm Post subject: |
|
|
Thanks. This looks like it is including 'pq' as a library to be linked. Can you see the "-lpq" switch given to gcc?
However, I can see you are also compiling all the phobos modules too. By default, it expects that the phobos modules are kept in a directory with the word 'phobos' in it, and thus excludes them from recompiling. You can alter this by adding "-Xdmdincludes" to either the Bud command line or more conveniently to the Bud configuration file (build.cfg). See the docs for details.
Have you still got a problem? _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Mon Dec 18, 2006 7:15 pm Post subject: |
|
|
This is the output from my hacked version of bud. If you'd like the vanilla output, I can post that too. [/i] |
|
Back to top |
|
|
mmcdermo
Joined: 09 Nov 2006 Posts: 18
|
Posted: Mon Dec 18, 2006 7:23 pm Post subject: |
|
|
It appears as if this bug has been debunked. I downloaded a fresh copy of 3.04 to do a vanilla verbose output on btest.d and it worked. I'm a bit confused. In any case, thank you for your help, Derek. |
|
Back to top |
|
|
|