www.digitalmars.com         C & C++   DMDScript  

D - D in Linux

reply John <John_member pathlink.com> writes:
Yo --

I'm trying to compile the following source:

int main(char[][] args)
{
return 0;
}

And I get a couple of unresolved externals:

$ dmd main.d
gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib 
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
: undefined reference to `_d_assert'
collect2: ld returned 1 exit status

As far as I can tell, I'm following the documentation pretty closely.  Does
anyone know what I'm doing wrong?

-- John
Feb 09 2004
parent reply "Walter" <walter digitalmars.com> writes:
It looks like libphobos.a is not being found. Did you put it in /usr/lib ?

"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18): In
 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty closely.

 anyone know what I'm doing wrong?

 -- John

Feb 09 2004
parent reply John <John_member pathlink.com> writes:
It's finding it -- it would say 'could not find -lphobos' when it couldn't.

Anyone have any other ideas?

In article <c09150$1c2k$1 digitaldaemon.com>, Walter says...
It looks like libphobos.a is not being found. Did you put it in /usr/lib ?

"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18): In
 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty closely.

 anyone know what I'm doing wrong?

 -- John


Feb 09 2004
next sibling parent reply Ant <duitoolkit yahoo.ca> writes:
On Mon, 09 Feb 2004 23:16:45 +0000, John wrote:

 It's finding it -- it would say 'could not find -lphobos' when it couldn't.
 
 Anyone have any other ideas?
 
 In article <c09150$1c2k$1 digitaldaemon.com>, Walter says...
It looks like libphobos.a is not being found. Did you put it in /usr/lib ?

"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18): In
 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty closely.

 anyone know what I'm doing wrong?

 -- John



you need something like: dmd main.d -I~/dmd/src/phobos
Feb 09 2004
parent John <John_member pathlink.com> writes:
I've got that in my dmd.conf:

[Environment]

DFLAGS=-I/opt/dmd/src/phobos -L-L/opt/dmd/lib

I don't think the problem is of the nature 'can't find some file.'  It gets to
the linking stage, and when it throws everything together, there are some
unresolved externals.  If it couldn't find some file I'm sure it would complain
specifically about that.

-- John

In article <pan.2004.02.09.23.31.43.879205 yahoo.ca>, Ant says...
On Mon, 09 Feb 2004 23:16:45 +0000, John wrote:

 It's finding it -- it would say 'could not find -lphobos' when it couldn't.
 
 Anyone have any other ideas?
 

you need something like: dmd main.d -I~/dmd/src/phobos

Feb 09 2004
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
Those unresolved symbols are in libphobos.a.

"John" <John_member pathlink.com> wrote in message
news:c094ct$1h9n$1 digitaldaemon.com...
 It's finding it -- it would say 'could not find -lphobos' when it

 Anyone have any other ideas?

 In article <c09150$1c2k$1 digitaldaemon.com>, Walter says...
It looks like libphobos.a is not being found. Did you put it in /usr/lib


"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18):



 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty closely.

 anyone know what I'm doing wrong?

 -- John



Feb 10 2004
parent reply John <John_member pathlink.com> writes:
This is what happens when I change dmd.conf so that it can no longer find
libphobos.a:

/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-linux-gnu/bin/ld:
cannot find -lphobos

So I'm rather positive that it's finding libphobos.a normally...

-- John

In article <c0a4p0$64a$1 digitaldaemon.com>, Walter says...
Those unresolved symbols are in libphobos.a.

"John" <John_member pathlink.com> wrote in message
news:c094ct$1h9n$1 digitaldaemon.com...
 It's finding it -- it would say 'could not find -lphobos' when it

 Anyone have any other ideas?

 In article <c09150$1c2k$1 digitaldaemon.com>, Walter says...
It looks like libphobos.a is not being found. Did you put it in /usr/lib


"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18):



 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty closely.

 anyone know what I'm doing wrong?

 -- John




Feb 10 2004
parent reply John <John_member pathlink.com> writes:
Okay, I think I've got at least some part of it fixed.  Apparently, when linking
with static libraries (I'm pretty sure dynamic libraries don't have this
problem), the order in which they're given to the linker is important.  By
default, D executes

gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib

Whereas libphobos needs to be placed before main.o.  When I run GCC myself and
rearrange things to look like

gcc -L/opt/dmd/lib -lphobos -lpthread -lm -Xlinker main.o -o main

Then I'm down to one unresolved external:

main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
: undefined reference to `_d_assert'

So it looks like now it's finding main -- but obviously I'm still having trouble
with _d_assert.  Is this also part of libphobos?  Is there a debug library I
need to link against to get _d_assert?

Thanks much,
John

In article <c0a4p0$64a$1 digitaldaemon.com>, Walter says...
Those unresolved symbols are in libphobos.a.

"John" <John_member pathlink.com> wrote in message
news:c094ct$1h9n$1 digitaldaemon.com...
 It's finding it -- it would say 'could not find -lphobos' when it

 Anyone have any other ideas?

 In article <c09150$1c2k$1 digitaldaemon.com>, Walter says...
It looks like libphobos.a is not being found. Did you put it in /usr/lib


"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../crt1.o(.text+0x18):



 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty closely.

 anyone know what I'm doing wrong?

 -- John





Feb 10 2004
parent reply "Walter" <walter digitalmars.com> writes:
_d_assert is defined by module std.asserterror, and it should be in the
library.

(To find where names are defined, the following is very handy:
    cd \dmd\src\phobos
    grep -r d_assert *.d
)


"John" <John_member pathlink.com> wrote in message
news:c0cj4h$14eg$1 digitaldaemon.com...
 Okay, I think I've got at least some part of it fixed.  Apparently, when

 with static libraries (I'm pretty sure dynamic libraries don't have this
 problem), the order in which they're given to the linker is important.  By
 default, D executes

 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib

 Whereas libphobos needs to be placed before main.o.  When I run GCC myself

 rearrange things to look like

 gcc -L/opt/dmd/lib -lphobos -lpthread -lm -Xlinker main.o -o main

 Then I'm down to one unresolved external:

 main.o(.gnu.linkonce.t_assert_4main+0x11): In function `_assert_4main':
 : undefined reference to `_d_assert'

 So it looks like now it's finding main -- but obviously I'm still having

 with _d_assert.  Is this also part of libphobos?  Is there a debug library

 need to link against to get _d_assert?

 Thanks much,
 John

In article <c0a4p0$64a$1 digitaldaemon.com>, Walter says...
Those unresolved symbols are in libphobos.a.

"John" <John_member pathlink.com> wrote in message
news:c094ct$1h9n$1 digitaldaemon.com...
 It's finding it -- it would say 'could not find -lphobos' when it

 Anyone have any other ideas?

 In article <c09150$1c2k$1 digitaldaemon.com>, Walter says...
It looks like libphobos.a is not being found. Did you put it in





?
"John" <John_member pathlink.com> wrote in message
news:c08t30$155e$1 digitaldaemon.com...
 Yo --

 I'm trying to compile the following source:

 int main(char[][] args)
 {
 return 0;
 }

 And I get a couple of unresolved externals:

 $ dmd main.d
 gcc main.o -o main -lphobos -lpthread -lm -Xlinker -L/opt/dmd/lib






In
 function `_start':
 : undefined reference to `main'
 main.o(.gnu.linkonce.t_assert_4main+0x11): In function






 : undefined reference to `_d_assert'
 collect2: ld returned 1 exit status

 As far as I can tell, I'm following the documentation pretty






Does
 anyone know what I'm doing wrong?

 -- John






Feb 12 2004
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Walter wrote:
 _d_assert is defined by module std.asserterror, and it should be in the
 library.
 
 (To find where names are defined, the following is very handy:
     cd \dmd\src\phobos
     grep -r d_assert *.d
 )

Just a minor clarification: the command should be grep -r d_assert . With -r (recurse), grep takes directories as arguments. You can pass it files as arguments, but it won't recurse into directories unles you give them on the command line. Russ
Feb 12 2004
next sibling parent "Walter" <walter digitalmars.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:c0glon$1r5i$1 digitaldaemon.com...
 Walter wrote:
 _d_assert is defined by module std.asserterror, and it should be in the
 library.

 (To find where names are defined, the following is very handy:
     cd \dmd\src\phobos
     grep -r d_assert *.d
 )

Just a minor clarification: the command should be grep -r d_assert . With -r (recurse), grep takes directories as arguments. You can pass it files as arguments, but it won't recurse into directories unles you give them on the command line.

Linux grep does work like that, you're right, but the win32 grep that I wrote works like the former <g>. In any case, grep is an underappreciated utility.
Feb 12 2004
prev sibling parent "C" <dont respond.com> writes:
One more addition

grep -rn d_assert .

gives line numbers also very handy :).

C
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:c0glon$1r5i$1 digitaldaemon.com...
 Walter wrote:
 _d_assert is defined by module std.asserterror, and it should be in the
 library.

 (To find where names are defined, the following is very handy:
     cd \dmd\src\phobos
     grep -r d_assert *.d
 )

Just a minor clarification: the command should be grep -r d_assert . With -r (recurse), grep takes directories as arguments. You can pass it files as arguments, but it won't recurse into directories unles you give them on the command line. Russ

Feb 12 2004