www.digitalmars.com         C & C++   DMDScript  

D - DMD on Openbsd w/ Linux emulation

reply Chris Lawson <cl mangler.tinfoilhat.ca> writes:
I don't expect a lot of help on this - and I'll probably end up coding 
in D under Windows with cygwin,  but if someone can help that would be 
great.

I'm trying to run DMD (0.79) on an OpenBSD machine using Linux 
emulation.  The compiler runs, but the OpenBSD linker doesn't seem to 
like libphobos.a

When I run ldconfig to include /dmd/lib in its search path (ldconfig -m 
/dmd/lib) the path shows up when I check ldconfig's status (ldconfig -r) 
but there is no entry for phobos.

Here's the output when I try to compile the sample hello.d:
#dmd hello.d
gcc hello.o -o hello -lphobos -lpthread -lm
/usr/bin/ld: cannot find -lphobos
collect2: ld returned 1 exit status
--- errorlevel 256

And here is the output when I run the gcc command by hand, telling it 
where I think libphobos is:
#gcc hello.o -o hello -lphobos -lpthread -lm -L /dmd/lib/
/dmd/lib//libphobos.a(gclinux.o): In function 
`_D7gclinux20os_query_stackBottomFZPv':
gclinux.o(.gnu.linkonce.t_D7gclinux20os_query_stackBottomFZPv+0x4): 
undefined reference to `__libc_stack_end'
/dmd/lib//libphobos.a(gclinux.o): In function 
`_D7gclinux22os_query_staticdatasegFPPvPkZv':
gclinux.o(.gnu.linkonce.t_D7gclinux22os_query_staticdatasegFPPvPkZv+0x8): 
undefined reference to `__data_start'
/dmd/lib//libphobos.a(monitor.o): In function `_d_monitorenter':
monitor.o(.text+0x8d): undefined reference to `__assert_fail'
/dmd/lib//libphobos.a(monitor.o): In function `_d_monitorexit':
monitor.o(.text+0x113): undefined reference to `__assert_fail'
/dmd/lib//libphobos.a(thread.o): In function 
`_D3std6thread6Thread11_staticCtorFZv':
thread.o(.gnu.linkonce.t_D3std6thread6Thread11_staticCtorFZv+0x42): 
undefined reference to `__libc_stack_end'
collect2: ld returned 1 exit status

Thanks in advance for any help.

Chris
Feb 26 2004
next sibling parent "Ben Hinkle" <bhinkle4 juno.com> writes:
"Chris Lawson" <cl mangler.tinfoilhat.ca> wrote in message
news:c1me73$2von$1 digitaldaemon.com...
| I don't expect a lot of help on this - and I'll probably end up coding
| in D under Windows with cygwin,  but if someone can help that would be
| great.
|
| I'm trying to run DMD (0.79) on an OpenBSD machine using Linux
| emulation.  The compiler runs, but the OpenBSD linker doesn't seem to
| like libphobos.a
|
| When I run ldconfig to include /dmd/lib in its search path (ldconfig -m
| /dmd/lib) the path shows up when I check ldconfig's status (ldconfig -r)
| but there is no entry for phobos.
|
| Here's the output when I try to compile the sample hello.d:
| #dmd hello.d
| gcc hello.o -o hello -lphobos -lpthread -lm
| /usr/bin/ld: cannot find -lphobos
| collect2: ld returned 1 exit status
| --- errorlevel 256
|
| And here is the output when I run the gcc command by hand, telling it
| where I think libphobos is:
| #gcc hello.o -o hello -lphobos -lpthread -lm -L /dmd/lib/
| /dmd/lib//libphobos.a(gclinux.o): In function
| `_D7gclinux20os_query_stackBottomFZPv':
| gclinux.o(.gnu.linkonce.t_D7gclinux20os_query_stackBottomFZPv+0x4):
| undefined reference to `__libc_stack_end'
| /dmd/lib//libphobos.a(gclinux.o): In function
| `_D7gclinux22os_query_staticdatasegFPPvPkZv':
| gclinux.o(.gnu.linkonce.t_D7gclinux22os_query_staticdatasegFPPvPkZv+0x8):
| undefined reference to `__data_start'
| /dmd/lib//libphobos.a(monitor.o): In function `_d_monitorenter':
| monitor.o(.text+0x8d): undefined reference to `__assert_fail'
| /dmd/lib//libphobos.a(monitor.o): In function `_d_monitorexit':
| monitor.o(.text+0x113): undefined reference to `__assert_fail'
| /dmd/lib//libphobos.a(thread.o): In function
| `_D3std6thread6Thread11_staticCtorFZv':
| thread.o(.gnu.linkonce.t_D3std6thread6Thread11_staticCtorFZv+0x42):
| undefined reference to `__libc_stack_end'
| collect2: ld returned 1 exit status
|
| Thanks in advance for any help.
|
| Chris

I don't know how the Linux emulator works, but my guess is it has a
library you need to pass to the linker, too.
Another possible option is to rebuild phobos.
Good luck,
-Ben
Feb 27 2004
prev sibling next sibling parent "Walter" <walter digitalmars.com> writes:
It doesn't look like a problem with libphobos.a, but a problem with putting
it in the right place so the linker can find it.
Feb 27 2004
prev sibling parent reply Chris Lawson <cl mangler.tinfoilhat.ca> writes:
Ok, I've rebuilt phobos.  I've got phobos in /usr/lib/, and I'm pretty 
sure gcc is finding it, given the error output.

Before I paste in my errors I just want to comment on what I had to do 
to rebuild phobos.  Hopefully this helps someone else along the way:
- Renamed all the linux.mak files to Makefile, so that gmake would 
recognize them.
- Stripped all the ^M characters out of all the files because they 
sometimes cause compilation problems (usually on lines ending with a \). 
  There's few enough of these problems that you can do it by hand, but 
I'll post a perl script that should help.
- For 'gmake clean' I had to change some instances of "del" in the 
makefile to "rm".

Then I copied the library to /usr/lib and ran ldconfig -R (this is 
highly system dependant, so read your ldconfig man page).

Here are the errors I get:

#dmd hello.d
gcc hello.o -o hello -lphobos -lpthread -lm
/usr/lib/libphobos.a(dmain2.o): In function `main':
dmain2.o(.gnu.linkonce.tmain+0x10): undefined reference to 
`_STI_monitor_staticctor'
dmain2.o(.gnu.linkonce.tmain+0x15): undefined reference to 
`_STI_critical_init'
dmain2.o(.gnu.linkonce.tmain+0x9d): undefined reference to 
`_STD_critical_term'
dmain2.o(.gnu.linkonce.tmain+0xa2): undefined reference to 
`_STD_monitor_staticdtor'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC6mallocFkZPv':
gcx.o(.gnu.linkonce.t_D3gcx2GC6mallocFkZPv+0x20): undefined reference to 
`_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC6mallocFkZPv+0x11b): undefined reference 
to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC4freeFPvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC4freeFPvZv+0x46): undefined reference to 
`_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC4freeFPvZv+0xdf): undefined reference to 
`_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC5checkFPvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC5checkFPvZv+0x1a): undefined reference to 
`_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC5checkFPvZv+0x32): undefined reference to 
`_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC7addRootFPvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC7addRootFPvZv+0x17): undefined reference 
to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC7addRootFPvZv+0x34): undefined reference 
to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC10removeRootFPvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC10removeRootFPvZv+0x17): undefined 
reference to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC10removeRootFPvZv+0x34): undefined 
reference to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC8addRangeFPvPvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC8addRangeFPvPvZv+0x17): undefined 
reference to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC8addRangeFPvPvZv+0x37): undefined 
reference to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC11removeRangeFPvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC11removeRangeFPvZv+0x17): undefined 
reference to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC11removeRangeFPvZv+0x34): undefined 
reference to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC11fullCollectFZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC11fullCollectFZv+0x17): undefined 
reference to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC11fullCollectFZv+0x31): undefined 
reference to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC10genCollectFZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC10genCollectFZv+0x17): undefined reference 
to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC10genCollectFZv+0x31): undefined reference 
to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function 
`_D3gcx2GC12setFinalizerFPvPFPvPvZvZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC12setFinalizerFPvPFPvPvZvZv+0x17): 
undefined reference to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC12setFinalizerFPvPFPvPvZvZv+0x3c): 
undefined reference to `_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC6enableFZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC6enableFZv+0x17): undefined reference to 
`_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC6enableFZv+0x2f): undefined reference to 
`_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC7disableFZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC7disableFZv+0x17): undefined reference to 
`_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC7disableFZv+0x2f): undefined reference to 
`_d_monitorexit'
/usr/lib/libphobos.a(gcx.o): In function 
`_D3gcx2GC8getStatsFJS7gcstats7GCStatsZv':
gcx.o(.gnu.linkonce.t_D3gcx2GC8getStatsFJS7gcstats7GCStatsZv+0x2b): 
undefined reference to `_d_monitorenter'
gcx.o(.gnu.linkonce.t_D3gcx2GC8getStatsFJS7gcstats7GCStatsZv+0xba): 
undefined reference to `_d_monitorexit'
/usr/lib/libphobos.a(gclinux.o): In function 
`_D7gclinux20os_query_stackBottomFZPv':
gclinux.o(.gnu.linkonce.t_D7gclinux20os_query_stackBottomFZPv+0x4): 
undefined reference to `__libc_stack_end'
/usr/lib/libphobos.a(gclinux.o): In function 
`_D7gclinux22os_query_staticdatasegFPPvPkZv':
gclinux.o(.gnu.linkonce.t_D7gclinux22os_query_staticdatasegFPPvPkZv+0x5): 
undefined reference to `__data_start'
/usr/lib/libphobos.a(thread.o): In function `_D3std6thread6Thread5startFZv':
thread.o(.gnu.linkonce.t_D3std6thread6Thread5startFZv+0x2d): undefined 
reference to `_d_monitorenter'
thread.o(.gnu.linkonce.t_D3std6thread6Thread5startFZv+0x8b): undefined 
reference to `_d_monitorexit'
/usr/lib/libphobos.a(thread.o): In function 
`_D3std6thread6Thread7getThisFZC3std6thread6Thread':
thread.o(.gnu.linkonce.t_D3std6thread6Thread7getThisFZC3std6
hread6Thread+0x1a): 
undefined reference to `_d_monitorenter'
thread.o(.gnu.linkonce.t_D3std6thread6Thread7getThisFZC3std6
hread6Thread+0x6f): 
undefined reference to `_d_monitorexit'
/usr/lib/libphobos.a(thread.o): In function 
`_D3std6thread6Thread11_staticCtorFZv':
thread.o(.gnu.linkonce.t_D3std6thread6Thread11_staticCtorFZv+0x42): 
undefined reference to `__libc_stack_end'
thread.o(.gnu.linkonce.t_D3std6thread6Thread11_staticCtorFZv+0x57): 
undefined reference to `_d_monitorenter'
thread.o(.gnu.linkonce.t_D3std6thread6Thread11_staticCtorFZv+0x81): 
undefined reference to `_d_monitorexit'
collect2: ld returned 1 exit status
--- errorlevel 256


Thanks again,
Chris
Mar 02 2004
next sibling parent Chris Lawson <cl mangler.tinfoilhat.ca> writes:
Chris Lawson wrote:

 I'll post a perl script that should help.

Here it is: #!/usr/bin/perl -w # Will recurse through a list of directories given as # command-line arguments and strip all ^M character # out of files it thinks are ASCII my $mv = "/bin/mv"; use strict; use File::Find; for my $dir ( ARGV ) { find(\&fix, $dir); } sub fix { my $file = $_; if ( -T $_ ) { my $fixed_name = $file . ".fixed"; open(INPUT, $file) or die "Unable to open $file"; open(OUTPUT, ">", $fixed_name) or die "Unable to write output"; while (<INPUT>) { $_ =~ s/\cM//; print OUTPUT; } close INPUT; close OUTPUT; if ( system($mv .' '. $fixed_name .' '. $file) ) { die "Unable to rename " . $File::Find::dir . $fixed_name; } } }
Mar 02 2004
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Chris Lawson" <cl mangler.tinfoilhat.ca> wrote in message
news:c22o6h$e4q$1 digitaldaemon.com...
 /usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC6mallocFkZPv':
 gcx.o(.gnu.linkonce.t_D3gcx2GC6mallocFkZPv+0x20): undefined reference to
 `_d_monitorenter'

These kinds of problems are pretty easy to find - after all, the library source is all there. Just grep for where _d_monitorenter is across the library source. (it's in internal/monitor.c, I'm guessing the Makefile isn't building monitor.o.) I'll once again tout grep as probably the most useful program development tool <g>.
Mar 02 2004
parent Chris Lawson <cl mangler.tinfoilhat.ca> writes:
Hi Walter,

I did a bunch of looking (grepping in fact!) after posting yesterday. 
I'm not sure that I completely understand how C works (which perhaps is 
not good), but all the symbols that couldn't be found ended up being 
extern(C), so I think that they're not implemented/available in the libc 
that I'm using.  I'll keep trying to figure this all out.

Thanks for your (and Ben's) advice!

Chris

Walter wrote:

 "Chris Lawson" <cl mangler.tinfoilhat.ca> wrote in message
 news:c22o6h$e4q$1 digitaldaemon.com...
 
/usr/lib/libphobos.a(gcx.o): In function `_D3gcx2GC6mallocFkZPv':
gcx.o(.gnu.linkonce.t_D3gcx2GC6mallocFkZPv+0x20): undefined reference to
`_d_monitorenter'

These kinds of problems are pretty easy to find - after all, the library source is all there. Just grep for where _d_monitorenter is across the library source. (it's in internal/monitor.c, I'm guessing the Makefile isn't building monitor.o.) I'll once again tout grep as probably the most useful program development tool <g>.

Mar 03 2004