FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

scons and mango

 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  
Author Message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Wed May 05, 2004 10:06 pm    Post subject: scons and mango Reply with quote

I feel like a freaking moron. I'm trying to link libmango.a or libmango.so into a small project with one D file.

Here's my setup:

/bb1/lib/libmango.a (or sometimes I try libmango.so)
/bb1/src/bb.d
/SConstruct

in SConstruct:
Code:
Program('bb1/src/bb.d', LIBS='mango', LIBPATH='bb1/lib')


in bb.d:
Code:
module bb;

import mango.io.socket;

void testHttpClient2 ()
{
        // create a socket and connect it to Walter's site
        SocketConduit sc = new SocketConduit();
        sc.connect (new InternetAddress("www.digitalmars.com", 80));

        // construct a (flushing) writer and bind it to the socket
        Writer w = new DisplayWriter (new FlushBuffer (256, sc));
       
        // send HTTP request
        w.put ("GET /d/intro.html HTTP/1.1")
         .cr  ()
         .put ("Host: www.digitalmars.com")
         .cr  ()
         .cr  ();

        // set read-timeout to 1 second (avoids stalling for ever!)
        sc.setTimeout (1_000_000);

        // create an input buffer
        IBuffer buffer = sc.createBuffer();
       
        // extract all headers
        HttpInputHeaders headers = new HttpInputHeaders();
        headers.parse (buffer);

        // display parsed headers -- these should match HttpHeader.HttpHeaders
        foreach (HeaderElement header; headers)
                 Stdout.put (header.name.value)
                       .put (header.value)
                       .cr  ();

        // display remaining content
        while (sc.read (buffer) != sc.Eof)
              {
              Stdout.put (buffer.toString());
              buffer.clear ();
              }
}

void main() {
   testHttpClient2();
}


And the error:
Code:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
dmd -I. -c -ofbb1/src/bb.o bb1/src/bb.d
Error: Error reading file 'mango/io/socket.d'

scons: building terminated because of errors.
scons: *** [bb1/src/bb.o] Error 1


I've compiled the mango lib with this:
Code:
from glob import glob
import os

env = Environment(ENV=os.environ)

SRC = (
    glob('mango/cache/*.d') +
    glob('mango/cache/*/*.d') +
    glob('mango/io/*.d') +
    glob('mango/io/*/*.d') +
    glob('mango/server/*.d') +
    glob('mango/server/*/*.d') +
    glob('mango/server/*/*/*.d') +
    glob('mango/servlet/*.d') +
    glob('mango/servlet/*/*.d')
)

env.SharedLibrary('mango',SRC)


Ideas?
_________________
I really like the vest!
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Thu May 06, 2004 1:22 pm    Post subject: Re: scons and mango Reply with quote

Brad, I'm not too familiar with SCons yet, but it nice to see how readible the scripts are. A couple of things that caught my eye (don't know how significant it is):

brad wrote:
I feel like a freaking moron. I'm trying to link libmango.a or libmango.so into a small project with one D file.

Here's my setup:

/bb1/lib/libmango.a (or sometimes I try libmango.so)
/bb1/src/bb.d
/SConstruct


Share libraries *.so apparently can't be generated with dmd on linux yet, so I wonder how you are doing that above.

brad wrote:
<snip code>

And the error:
[code]scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
dmd -I. -c -ofbb1/src/bb.o bb1/src/bb.d
Error: Error reading file 'mango/io/socket.d'

scons: building terminated because of errors.
scons: *** [bb1/src/bb.o] Error 1


One of the problems, I think, is that you haven't pointed the compiler to the mango source directory. You have moved the libmango.a to your new project directory and dmd still needs to see the Mango definitions for the compile phase . Perhaps you can try a -I<basedir>/mango on the compile line where <basedir> is replaced with the path to the mango source. It doesn't appear that SCons is doing this for you.

Another thing about the above line:

dmd -I. -c ofbb1/src/bb.o bb1/src/bb.d

is compile only and is not linking in libmango.a with it as in...

dmd ofbb1/src/bb.o bb1/src/bb.d libmango.a

Perhaps that's intentional and I'm just not following...

brad wrote:
I've compiled the mango lib with this:
[code]from glob import glob
import os

env = Environment(ENV=os.environ)

SRC = (
glob('mango/cache/*.d') +
glob('mango/cache/*/*.d') +
glob('mango/io/*.d') +
glob('mango/io/*/*.d') +
glob('mango/server/*.d') +
glob('mango/server/*/*.d') +
glob('mango/server/*/*/*.d') +
glob('mango/servlet/*.d') +
glob('mango/servlet/*/*.d')
)

env.SharedLibrary('mango',SRC)[/code]

Ideas?


How are you making a shared library. According to the digitalmars site, Linux dmd doesn't support the making of shared libraries yet. Is it working?
Back to top
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Thu May 06, 2004 3:10 pm    Post subject: Reply with quote

scons did the libmango.so - maybe by using GNU make. Who knows, it may not work properly, so I'll concentrate on libmango.a

I'll also try a few different things, but I believe scons builds in the -c and then tries to link after the fact, possibly with something other than dmd or dm make.
_________________
I really like the vest!
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Thu May 06, 2004 4:00 pm    Post subject: Reply with quote

brad wrote:
scons did the libmango.so - maybe by using GNU make. Who knows, it may not work properly, so I'll concentrate on libmango.a


Well, I think Scons did the shared library thing because of...

env.SharedLibrary('mango',SRC)

in the SConscripts file. Is this file auto generated then? SCons settings must be editable.

My question would be why does scons need "make." I thought scons was supposed to replace make.

brad wrote:
I'll also try a few different things, but I believe scons builds in the -c and then tries to link after the fact, possibly with something other than dmd or dm make.


There's no such thing as dm make on Linux. GNU make is the default one. As for linking, there's only one way possible, I thought... that is by using the "gcc" command which automatically calls the linker -- ld, I believe. SCons probably does that automatically.

I'll have to read up on SCons and get a better understanding of it. How are you finding it? Do you think it's worth using instead of make yet?


Last edited by JJR on Thu May 06, 2004 4:07 pm; edited 1 time in total
Back to top
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Thu May 06, 2004 4:07 pm    Post subject: Reply with quote

JJR wrote:
Well, I think Scons did the shared library thing because of...

env.SharedLibrary('mango',SRC)

By design. I use StaticLibrary when I want to make libmango.a

JJR wrote:
My question would be why does scons need "make." I thought scons was supposed to replace make.

Hmm. That's me being a block-head again. Maybe I meant "link" or "ar" or similar.


JJR wrote:
There's no dm make on Linux. GNU make is usually the default one provided.

ibid on the blockhead thing.

JJR wrote:
I'll have to read up on SCons and get a better understanding of it. How are you finding it? Do you think it's worth using instead of make yet?


Oh yeah, I'll be using it. But like you, I have to read up on it more, and figure out how to use it. Wildcards, and a scripting language in general, are two powerful reasons for me. And like you said, the files are very readable.

Maybe scons isn't handling linking a library correctly yet. I'll be looking as well, so let's continue to post here. Maybe Andy will see it and lend a hand.
_________________
I really like the vest!
Back to top
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Thu May 06, 2004 4:19 pm    Post subject: Reply with quote

brad wrote:
Hmm. That's me being a block-head again. Maybe I meant "link" or "ar" or similar.


Nothing of the sort. Just a little miss... the linux linker is "ld." "ar" is the library builder/archiver. It allows you to pack all the *.o files like sardines in a can to create libmango.a. So you're right: SCons likely calls both those tools to build the project library.

brad wrote:
Oh yeah, I'll be using it. But like you, I have to read up on it more, and figure out how to use it. Wildcards, and a scripting language in general, are two powerful reasons for me. And like you said, the files are very readable.

Maybe scons isn't handling linking a library correctly yet. I'll be looking as well, so let's continue to post here. Maybe Andy will see it and lend a hand.


Ok....look forward to hearing about the solution...
Back to top
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Wed May 12, 2004 5:42 pm    Post subject: Reply with quote

I capitalized Socket in my import statement in bb.d, but still have issues.

Now I put a symbolic link in the bb1/lib folder to my mango source.

I'm also trying different things with libmango.a, like putting it in /usr/lib and using this SConstruct file:

Code:
from glob import glob
import os

env = Environment(ENV=os.environ)

SRC = (
   glob('bb1/src/bb.d') +
   glob('bb1/lib/mango/io/*.d') +
   glob('bb1/lib/mango/io/*/*.d')
)

env.Program('bb', SRC)


The error remains the same:
Code:
Error: Error reading file 'mango/io/Socket.d'

_________________
I really like the vest!
Back to top
View user's profile Send private message
andy



Joined: 15 Mar 2004
Posts: 71

PostPosted: Wed May 12, 2004 5:51 pm    Post subject: Reply with quote

You forgot to set the DPATH.

Code:
from glob import glob
import os

# you can set DPATH like this:
env = Environment(ENV=os.environ, DPATH='path/to/mango/src')

# or like this:
env.Append(DPATH='path/to/mango/src')

SRC = (
   glob('bb1/src/bb.d') +
   glob('bb1/lib/mango/io/*.d') +
   glob('bb1/lib/mango/io/*/*.d')
)

env.Program('bb', SRC)

_________________
"Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear


Last edited by andy on Wed May 12, 2004 9:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Wed May 12, 2004 6:38 pm    Post subject: Reply with quote

That did it. Thanks, Andy !

btw, as you've been saying for a while, SCons rules...
_________________
I really like the vest!
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu May 20, 2004 9:30 am    Post subject: Reply with quote

Hi Brad,

Would it be OK if your SCons script were added to the Mango download? Also, since Chris S has one in there for Win32, is it possible to combine the two of them?

- Kris
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Thu May 20, 2004 10:21 am    Post subject: Reply with quote

Actually his should be useable for both platforms, perhaps after a little tweakage. Plus mine was written more to suit me (when I was compiling DSC as multiple libs early on), his is in the more maintainable format. I think it can be buried at sea now. Smile
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Thu May 20, 2004 10:20 pm    Post subject: Reply with quote

Here's my script:

Code:

from glob import glob
import os

env = Environment(ENV=os.environ)

SRC = (
    glob('mango/cache/*.d') +
    glob('mango/cache/*/*.d') +
    glob('mango/io/*.d') +
    glob('mango/io/*/*.d') +
    glob('mango/server/*.d') +
    glob('mango/server/*/*.d') +
    glob('mango/server/*/*/*.d') +
    glob('mango/servlet/*.d') +
    glob('mango/servlet/*/*.d')
)

env.StaticLibrary('mango',SRC)


and here are some proposed (and untested) changes for cross-platform...

Code:

from glob import glob
import os
import sys

env = Environment(ENV=os.environ)

SRC = (
    glob('mango/cache/*.d') +
    glob('mango/cache/*/*.d') +
    glob('mango/io/*.d') +
    glob('mango/io/*/*.d') +
    glob('mango/server/*.d') +
    glob('mango/server/*/*.d') +
    glob('mango/server/*/*/*.d') +
    glob('mango/servlet/*.d') +
    glob('mango/servlet/*/*.d')
)

if 'win32' in sys.platform:
    env.Append(DVERSIONS='Win32')
elif 'linux' in sys.platform:
    env.Append(DVERSIONS=['unix', 'linux'])

env.StaticLibrary('mango',SRC)


There is an issue, though. You have to check the project out into a folder called mango/mango and put these in the first mango folder. Or something like this:

/mango/trunk/mango/io
/mango/trunk/mango/server
/mango/trunk/SConstruct

It's all in how and where you check it out... I think there needs to be a mango folder in /trunk. I know it doesn't make a lot of sense to nest it this many times or have this many folders, but even the import module statements are looking for mango.io and mango.server, and would require this folder, right?
_________________
I really like the vest!
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu May 20, 2004 10:55 pm    Post subject: Reply with quote

brad wrote:
It's all in how and where you check it out... I think there needs to be a mango folder in /trunk. I know it doesn't make a lot of sense to nest it this many times or have this many folders, but even the import module statements are looking for mango.io and mango.server, and would require this folder, right?

There does indeed need to be a parent folder/directory from where the make/SCons files are executed (due to import restrictions vis-a-vis sibling packages). For now I'm using a dmd/src/mango/... setup and execute make from dmd/src, but that's not very clean.

Would appreciate additional ideas on how to resolve this kind of thing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group