Re: [9fans] 9P in C++

2008-12-17 Thread sqweek
On Thu, Dec 18, 2008 at 7:14 AM, Rodolfo kix Garcia  wrote:
> Pietro Gagliardi escribió:
>> extern "C"{
>> #include <9p.h> // or whatever you do
>> }
>>
>> you can link 9p into a C++ program easily.
>
> If I use the extern "C" it compiles :'-)
>
> Using "extern function" is not valid for linking C and C++


 extern works fine between C and C++, but maybe it doesn't do what you
think it does. extern assures the compiler that there is a symbol with
a certain type defined in some other object than the one currently
being compiled.
 What you're running into is a name mangling issue. C++ supports
overloaded functions, ie. functions with the same name but different
prototypes. This doesn't fly with the linker, because as far as it is
concerned each symbol has a unique type[1]. So, C++ mangles[2] the
function name by appending a string representation of the prototype.
int main(int, char**) maps to a symbol like main_i_i_ppc. The mangled
notation is compiler specific of course.
 This presents a problem for interoperation with C code. Any existing
library compiled by a C compiler has regular non-mangled names. But, a
C++ compiler will grab the prototypes from the library's header file,
and then tell the linker to look for mangled versions of the symbols.
Obviously it is not going to find them.
 So, as a workaround, C++ overloads the extern keyword to allow the form:
extern "C" {
...
}
 Which tells the compiler "the functions defined in this block were
compiled with a C compiler, don't mangle the symbols".

[1] Does the linker actually know about types or just sizes?
[2] "mangles" is official terminology, so at least they're honest about it. ;)

-sqweek


Re: [9fans] 9P in C++

2008-12-17 Thread Rodolfo kix Garcia

Pietro Gagliardi escribió:

Given

extern "C"{
#include <9p.h> // or whatever you do
}

you can link 9p into a C++ program easily.


Yes!

If I use the extern "C" it compiles :'-)

Using "extern function" is not valid for linking C and C++

Sorry Pietro, sqweek. Thanks a lot.




Re: [9fans] 9P in C++

2008-12-16 Thread kix

Thanks Pietro, sqweek,

I can't compile it :-/

Some info:

k...@sys:~/2008110109$ cat Makefile
all:
   g++ -Wall -fPIC -c a.C
   g++ -Wall -fPIC -c b.C
   g++ -Wall -fPIC -c c.C
   9c -Wall -o tryfs.o tryfs.c
   9l -Wall -shared -lthread -o libtry.so a.o b.o c.o tryfs.o 
/usr/local/plan9/lib/libthread.a

   g++ -Wall -g -o simple-01 simple-01.C -L. -l try -lstdc++


k...@sys:~/2008110109$ make
...
9l -Wall -shared -lthread -o libtry.so a.o b.o c.o tryfs.o 
/usr/local/plan9/lib/libthread.a

g++ -Wall -g -o simple-01 simple-01.C -L. -l try -lstdc++
./libtry.so: undefined reference to `threadmain(int, char**)'
collect2: ld returned 1 exit status
make: *** [all] Error 1

k...@sys:~/2008110109$  ldd libtry.so
   linux-gate.so.1 =>  (0xb7eed000)
   libresolv.so.2 => /lib/i686/cmov/libresolv.so.2 (0xb7ece000)
   libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb7ea8000)
   libutil.so.1 => /lib/i686/cmov/libutil.so.1 (0xb7ea3000)
   libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb7e8a000)
   libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7d2f000)
   /lib/ld-linux.so.2 (0xb7eee000)

In the tryfs.c file:

void
threadmain(int argc, char *argv[])
{
}

Thanks.


Pietro Gagliardi wrote:



-l/usr/local/plan9/lib/libthread.so (or whatever it is) help?


You can't use -l with a full path, but you can simply specify the
full path of the library:
gcc -o demo1 demo1.C /usr/local/plan9/lib/libthread.a
Note that the order of the objects on the command-line is as usual 
important.

-sqweek



Ah yes, something I forgot while drifting through the hordes of gcc 
madness that is... not using gcc. Thanks for refreshing my memory. Now 
to see if this is working for kix.







Re: [9fans] 9P in C++

2008-12-15 Thread Pietro Gagliardi

On Dec 15, 2008, at 9:16 PM, sqweek wrote:

On Tue, Dec 16, 2008 at 8:34 AM, Pietro Gagliardi   
wrote:

On Dec 15, 2008, at 6:25 PM, Rodolfo kix Garcia wrote:
gcc -L /usr/local/plan9/lib -L. -ltry -lthread demo1.C -o demo1   
## OK!


I think linking lthread will give you POSIX threads and that -L  
appends to
the list, rather than going before, so /usr/lib will be searched  
before

plan9ports. Try explicitly setting the path of the -l argument. Does
-l/usr/local/plan9/lib/libthread.so (or whatever it is) help?


You can't use -l with a full path, but you can simply specify the
full path of the library:
gcc -o demo1 demo1.C /usr/local/plan9/lib/libthread.a
Note that the order of the objects on the command-line is as usual  
important.

-sqweek



Ah yes, something I forgot while drifting through the hordes of gcc  
madness that is... not using gcc. Thanks for refreshing my memory. Now  
to see if this is working for kix.




PGP.sig
Description: This is a digitally signed message part


Re: [9fans] 9P in C++

2008-12-15 Thread sqweek
On Tue, Dec 16, 2008 at 8:34 AM, Pietro Gagliardi  wrote:
> On Dec 15, 2008, at 6:25 PM, Rodolfo kix Garcia wrote:
>> gcc -L /usr/local/plan9/lib -L. -ltry -lthread demo1.C -o demo1  ## OK!
>
> I think linking lthread will give you POSIX threads and that -L appends to
> the list, rather than going before, so /usr/lib will be searched before
> plan9ports. Try explicitly setting the path of the -l argument. Does
> -l/usr/local/plan9/lib/libthread.so (or whatever it is) help?

 You can't use -l with a full path, but you can simply specify the
full path of the library:
gcc -o demo1 demo1.C /usr/local/plan9/lib/libthread.a
 Note that the order of the objects on the command-line is as usual important.
-sqweek



Re: [9fans] 9P in C++

2008-12-15 Thread Pietro Gagliardi

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Dec 15, 2008, at 6:25 PM, Rodolfo kix Garcia wrote:

gcc -L /usr/local/plan9/lib -L. -ltry -lthread demo1.C -o demo1  ##  
OK!


I think linking lthread will give you POSIX threads and that -L  
appends to the list, rather than going before, so /usr/lib will be  
searched before plan9ports. Try explicitly setting the path of the -l  
argument. Does -l/usr/local/plan9/lib/libthread.so (or whatever it is)  
help?


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAklG6YAACgkQuv7AVNQDs+xs6QCfZy4CD480VMiv8DN2VyX2ydDs
WzYAn0sEgTbpQM9Z/8ieACzLVBx15okU
=Jzfc
-END PGP SIGNATURE-



Re: [9fans] 9P in C++

2008-12-15 Thread Rodolfo kix Garcia

Pietro Gagliardi escribió:

Given

extern "C"{
#include <9p.h> // or whatever you do
}

you can link 9p into a C++ program easily.


Thanks Pietro :-)

I use:

#include stdio.h
#include blablabla.h
extern void threadmain(int c, char *a[])

Now the file compiles. But I have other problem.

gcc -L. -ltry -o demo1 demo1.C
./libtry.so: Undefined reference to threadmain(...)

Then, I try:
gcc -L /usr/local/plan9/lib -L. -ltry -lthread demo1.C -o demo1  ## OK!
./demo1
Segmentation Fault

using ldd I can see libthread is /usr/lib/libthread, not in the 
plan9port three.


Any help?

Thanks a lot.



Re: [9fans] 9P in C++

2008-12-15 Thread Pietro Gagliardi

On Dec 15, 2008, at 10:45 AM, Rodolfo kix García wrote:


Hi!

I am working in an c++ application on linux and I would like to use a
filesystem to access to the application data.

Somebody knows any 9P implementation of 9P in C++?

Thanks,

Saludos, kix.


--
Rodolfo García AKA kix
http://www.kix.es/
EA4ERH (@IN80ER)




Given

extern "C"{
#include <9p.h> // or whatever you do
}

you can link 9p into a C++ program easily.



PGP.sig
Description: This is a digitally signed message part


Re: [9fans] 9P in C++

2008-12-15 Thread Iruata Souza
On Mon, Dec 15, 2008 at 1:45 PM, Rodolfo kix García  wrote:
> Hi!
>
> I am working in an c++ application on linux and I would like to use a
> filesystem to access to the application data.
>
> Somebody knows any 9P implementation of 9P in C++?
>

any issues with using the ones in C?

iru


Re: [9fans] 9P in C++

2008-12-15 Thread sqweek
On Tue, Dec 16, 2008 at 12:45 AM, Rodolfo kix García  wrote:
> Hi!
>
> I am working in an c++ application on linux and I would like to use a
> filesystem to access to the application data.
>
> Somebody knows any 9P implementation of 9P in C++?

 Don't see one at http://9p.cat-v.org/implementations
 Of course any C implementation like libixp will work fine.
-sqweek


[9fans] 9P in C++

2008-12-15 Thread Rodolfo kix García
Hi!

I am working in an c++ application on linux and I would like to use a
filesystem to access to the application data.

Somebody knows any 9P implementation of 9P in C++?

Thanks,

Saludos, kix.


-- 
Rodolfo García AKA kix
http://www.kix.es/
EA4ERH (@IN80ER)