Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 14, 2005 extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Here is a small main program + a subrouitne: if i compile with: dmd main bsderr the linker complains: bsderr.obj(bsderr) Error 42: Symbol Undefined _D6bsderr7programPa i tried may scenarios of compiling and linking... nothing works. Can someone explains how to make this working. Thanks /* --- main.d : main file --- */ char* program; import bsderr; int main( char[][] argv ) { program = argv[0]; warnx( "it works %s + %03d\n", cast(char*)"asdasdasd", 23 ); return 0; } /* --- bsderr.d : a subroutine --- */ import std.c.stdio; import std.c.stddef; import std.c.stdarg; extern char* program; /* defined in the main program */ void warnx( char* format, ... ) { va_list ap; va_start!(char*)(ap,format); if( program && *program ) fprintf( stderr, "%s: ", program ); vfprintf( stderr, format, ap ); va_end (ap); } |
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos | Carlos <carlos2003nov@yahoo.ca> wrote: [...] > the linker complains: > bsderr.obj(bsderr) > Error 42: Symbol Undefined _D6bsderr7programPa [...] Change extern char* program; to extern (D) char* program; ( http://www.digitalmars.com/d/attribute.html ) Issue commands dmd -c bsderr dmd main bsderr.obj -manfred |
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | On Mon, 14 Mar 2005 08:46:47 +0000 (UTC), Manfred Nowak <svv1999@hotmail.com> wrote:
> Carlos <carlos2003nov@yahoo.ca> wrote:
>
> [...]
>> the linker complains:
>> bsderr.obj(bsderr)
>> Error 42: Symbol Undefined _D6bsderr7programPa
> [...]
>
> Change
>
> extern char* program;
>
> to
>
> extern (D) char* program;
>
> ( http://www.digitalmars.com/d/attribute.html )
Does that mean "extern" is the same as "extern (C)"?
Because, from the above link:
<quote>
C function calling conventions are specified by:
extern (C):
int foo();call foo() with C conventions
D conventions are:
extern (D):
or:
extern:
</quote>
it seems to suggest "extern (D)" should be the same as "extern".
Regan
|
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos |
Carlos,
you may want to take a look at build.exe which will take away the need to provide
dmd source.d source0.d source1.d ... sourceN.d
to the simple and more beautiful command,
build source.0
and build.exe will do all the linking for you. I am loving this little but powerful application more and more each day.
Oh yeah, back to your problem: you need to specify that bsderr.d is piece of software that could be link. In top of you your bsderr.d file you need to specify this. With this simple command,
/* --- bsderr.d : a subroutine --- */
modudle bsderr;
import std.c.stdio;
import std.c.stddef;
import std.c.stdarg;
..
..
that should do it. One last piece of advice: you may want to privately import the libraries in your libraries. This simple means that instead of
import std.c.stdio;
import std.c.stddef;
import std.c.stdarg;
you now have
private import std.c.stdio;
private import std.c.stddef;
private import std.c.stdarg;
Just a thought...
thanks,
josé
Carlos says...
>
>Here is a small main program + a subrouitne:
>
>if i compile with:
>
> dmd main bsderr
>
>the linker complains:
> bsderr.obj(bsderr)
> Error 42: Symbol Undefined _D6bsderr7programPa
>
>i tried may scenarios of compiling and linking...
>nothing works.
>
>Can someone explains how to make this working.
>
>Thanks
>
>/* --- main.d : main file --- */
>char* program;
>import bsderr;
>int main( char[][] argv )
>{
> program = argv[0];
> warnx( "it works %s + %03d\n", cast(char*)"asdasdasd", 23 );
> return 0;
>}
>
>/* --- bsderr.d : a subroutine --- */
>import std.c.stdio;
>import std.c.stddef;
>import std.c.stdarg;
>
>extern char* program; /* defined in the main program */
>
>void warnx( char* format, ... )
>{
> va_list ap;
> va_start!(char*)(ap,format);
> if( program && *program )
> fprintf( stderr, "%s: ", program );
> vfprintf( stderr, format, ap );
> va_end (ap);
>}
|
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | "Regan Heath" <regan@netwin.co.nz> wrote:
[...]
> it seems to suggest "extern (D)" should be the same as "extern".
I agree. But the specs also say:
| C and D must be supplied
So the specs are ambiguous. However, a discussion on the specs wouldn't help Carlos.
-manfred
|
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | On Mon, 14 Mar 2005 08:46:47 +0000 (UTC), Manfred Nowak wrote: > Carlos <carlos2003nov@yahoo.ca> wrote: > > [...] >> the linker complains: >> bsderr.obj(bsderr) >> Error 42: Symbol Undefined _D6bsderr7programPa > [...] > > Change > > extern char* program; > > to > > extern (D) char* program; Curiously if you use "extern (C) char* program;" it also compiles and runs correctly. This might be a bug, in either dmd or the documentation. -- Derek Parnell Melbourne, Australia 14/03/2005 9:45:57 PM |
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to jicman | jicman wrote:
> Carlos,
>
> you may want to take a look at build.exe which will take away the need to
> provide
>
Yes, i known build.
I use it, and it's quite good.
That's utility has a future, for sure...
|
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | Manfred Nowak wrote:
> "Regan Heath" <regan@netwin.co.nz> wrote:
>
> [...]
>
>>it seems to suggest "extern (D)" should be the same as "extern".
>
>
> I agree. But the specs also say:
>
> | C and D must be supplied
>
> So the specs are ambiguous. However, a discussion on the specs wouldn't help Carlos.
>
> -manfred
I think that part of the specs, says:
"All implementations of D, must support at least two
linkage, ie: C and D. Others can be supported, but it's not
mandatory".
This could be clarified.
|
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote: > On Mon, 14 Mar 2005 08:46:47 +0000 (UTC), Manfred Nowak wrote: > > Curiously if you use "extern (C) char* program;" it also compiles and runs > correctly. This might be a bug, in either dmd or the documentation. > --[ Based on dmd 0.118 ]-- Yes i discovered that also. More, if you use extern (C) char*program; the whole thing can be compiled with one command: ie: dmd main bsderr but if you use extern (C) char*program; you must issue 2 separate commands ie: dmd -c main dmd main bsderr Also, This is two D files. I think "extern" is synonym of "extern (D)" because "D" is the default linkage if no one is specified. So, i think this is a bug ! |
March 14, 2005 Re: extern, how does it work ( linker says undefined ) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos | Carlos <carlos2003nov@yahoo.ca> wrote:
[...]
> "All implementations of D, must support at least two linkage, ie: C and D. Others can be supported, but it's not mandatory".
[...]
Agreed. Walter seems to have switched from a programmers point of view on D to a compiler writers point of view on D.
I this even clearer:
"Main linkage types are C and D. In addition under windows the linkage types Windows and Pascal exist. Further linkage types may exist."
-manfred
|
Copyright © 1999-2021 by the D Language Foundation