9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] 9P in C++
  2008-12-16  2:31         ` Pietro Gagliardi
@ 2008-12-13 21:18           ` kix
  0 siblings, 0 replies; 11+ messages in thread
From: kix @ 2008-12-13 21:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Thanks Pietro, sqweek,

I can't compile it :-/

Some info:

kix@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++


kix@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

kix@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.
>




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [9fans] 9P in C++
@ 2008-12-15 15:45 Rodolfo kix García 
  2008-12-15 16:56 ` sqweek
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Rodolfo kix García  @ 2008-12-15 15:45 UTC (permalink / raw)
  To: 9fans

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)




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 15:45 [9fans] 9P in C++ Rodolfo kix García 
@ 2008-12-15 16:56 ` sqweek
  2008-12-15 16:59 ` Iruata Souza
  2008-12-15 21:13 ` Pietro Gagliardi
  2 siblings, 0 replies; 11+ messages in thread
From: sqweek @ 2008-12-15 16:56 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, Dec 16, 2008 at 12:45 AM, Rodolfo kix García <kix@kix.es> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 15:45 [9fans] 9P in C++ Rodolfo kix García 
  2008-12-15 16:56 ` sqweek
@ 2008-12-15 16:59 ` Iruata Souza
  2008-12-15 21:13 ` Pietro Gagliardi
  2 siblings, 0 replies; 11+ messages in thread
From: Iruata Souza @ 2008-12-15 16:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Dec 15, 2008 at 1:45 PM, Rodolfo kix García <kix@kix.es> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 15:45 [9fans] 9P in C++ Rodolfo kix García 
  2008-12-15 16:56 ` sqweek
  2008-12-15 16:59 ` Iruata Souza
@ 2008-12-15 21:13 ` Pietro Gagliardi
  2008-12-15 23:25   ` Rodolfo kix Garcia
  2008-12-17 22:14   ` Rodolfo kix Garcia
  2 siblings, 2 replies; 11+ messages in thread
From: Pietro Gagliardi @ 2008-12-15 21:13 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


[-- Attachment #1.1: Type: text/plain, Size: 486 bytes --]

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.


[-- Attachment #1.2: Type: text/html, Size: 1038 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 201 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 21:13 ` Pietro Gagliardi
@ 2008-12-15 23:25   ` Rodolfo kix Garcia
  2008-12-15 23:34     ` Pietro Gagliardi
  2008-12-17 22:14   ` Rodolfo kix Garcia
  1 sibling, 1 reply; 11+ messages in thread
From: Rodolfo kix Garcia @ 2008-12-15 23:25 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 23:25   ` Rodolfo kix Garcia
@ 2008-12-15 23:34     ` Pietro Gagliardi
  2008-12-16  2:16       ` sqweek
  0 siblings, 1 reply; 11+ messages in thread
From: Pietro Gagliardi @ 2008-12-15 23:34 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

-----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-----



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 23:34     ` Pietro Gagliardi
@ 2008-12-16  2:16       ` sqweek
  2008-12-16  2:31         ` Pietro Gagliardi
  0 siblings, 1 reply; 11+ messages in thread
From: sqweek @ 2008-12-16  2:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, Dec 16, 2008 at 8:34 AM, Pietro Gagliardi <pietro10@mac.com> 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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-16  2:16       ` sqweek
@ 2008-12-16  2:31         ` Pietro Gagliardi
  2008-12-13 21:18           ` kix
  0 siblings, 1 reply; 11+ messages in thread
From: Pietro Gagliardi @ 2008-12-16  2:31 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


[-- Attachment #1.1: Type: text/plain, Size: 1011 bytes --]

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

> On Tue, Dec 16, 2008 at 8:34 AM, Pietro Gagliardi <pietro10@mac.com>
> 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.


[-- Attachment #1.2: Type: text/html, Size: 1584 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 201 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-15 21:13 ` Pietro Gagliardi
  2008-12-15 23:25   ` Rodolfo kix Garcia
@ 2008-12-17 22:14   ` Rodolfo kix Garcia
  2008-12-18  7:16     ` sqweek
  1 sibling, 1 reply; 11+ messages in thread
From: Rodolfo kix Garcia @ 2008-12-17 22:14 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] 9P in C++
  2008-12-17 22:14   ` Rodolfo kix Garcia
@ 2008-12-18  7:16     ` sqweek
  0 siblings, 0 replies; 11+ messages in thread
From: sqweek @ 2008-12-18  7:16 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, Dec 18, 2008 at 7:14 AM, Rodolfo kix Garcia <kix@kix.es> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-12-18  7:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-15 15:45 [9fans] 9P in C++ Rodolfo kix García 
2008-12-15 16:56 ` sqweek
2008-12-15 16:59 ` Iruata Souza
2008-12-15 21:13 ` Pietro Gagliardi
2008-12-15 23:25   ` Rodolfo kix Garcia
2008-12-15 23:34     ` Pietro Gagliardi
2008-12-16  2:16       ` sqweek
2008-12-16  2:31         ` Pietro Gagliardi
2008-12-13 21:18           ` kix
2008-12-17 22:14   ` Rodolfo kix Garcia
2008-12-18  7:16     ` sqweek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).