[libvirt] libvirt library binary name for linux

?Hi, I'm currently working on .Net / Mono bindings of libvirt. I know that under windows environment, the libvirt library binary is named "libvirt-0.dll", what is it under linux ? I suppose libvirt.so, but I can't find it... Arnaud

?Okay, I have found it, it's libvirt.so.0 I have also a libvirt.so.0.8.2, I suppose libvirt.so.0 is a link this. Another question, in my bindings I need the strdup function (pinvoked) and under windows, strdup is in msvcrt.dll, but where it is under linux ? Best regards, Arnaud From: arnaud.champion@devatom.fr Sent: Tuesday, October 19, 2010 1:10 PM To: libvir-list@redhat.com Subject: [libvirt] libvirt library binary name for linux Hi, I'm currently working on .Net / Mono bindings of libvirt. I know that under windows environment, the libvirt library binary is named "libvirt-0.dll", what is it under linux ? I suppose libvirt.so, but I can't find it... Arnaud -------------------------------------------------------------------------------- -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 10/19/2010 10:16 PM, arnaud.champion@devatom.fr wrote:
?Okay, I have found it, it's libvirt.so.0
I have also a libvirt.so.0.8.2, I suppose libvirt.so.0 is a link this.
Another question, in my bindings I need the strdup function (pinvoked) and under windows, strdup is in msvcrt.dll, but where it is under linux ?
Hi Arnaud, On a Fedora 13 Linux box, if I type the command "man strdup", it shows: NAME strdup, strndup, strdupa, strndupa - duplicate a string SYNOPSIS #include <string.h> char *strdup(const char *s); char *strndup(const char *s, size_t n); char *strdupa(const char *s); char *strndupa(const char *s, size_t n); <other stuff snipped> The string.h refers to /usr/include/string.h. I'm not sure which library file the code is in though. For most things it's not needed. Does any of the above help? :) Regards and best wishes, Justin Clift

On 10/19/2010 06:07 AM, Justin Clift wrote:
I'm not sure which library file the code is in though. For most things it's not needed.
glibc (that is, libc.so, which is pretty much universally linked in to every other program already). You don't need to add -lc to your compiler line, at any rate. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

?I have tried libc.so and it doesn't contains _strdup, amybe it's strdup instead I will try. Anyway I have a little question (a windowsian question :) ). Under windows I have a tool named "depends.exe" with it, I can sse what is exposed thru a dll, is there any equivalent under linux ? Arnaud -------------------------------------------------- From: "Eric Blake" <eblake@redhat.com> Sent: Tuesday, October 19, 2010 2:15 PM To: "Justin Clift" <jclift@redhat.com> Cc: <libvir-list@redhat.com> Subject: Re: [libvirt] libvirt library binary name for linux
On 10/19/2010 06:07 AM, Justin Clift wrote:
I'm not sure which library file the code is in though. For most things it's not needed.
glibc (that is, libc.so, which is pretty much universally linked in to every other program already). You don't need to add -lc to your compiler line, at any rate.
-- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

?Okay, I have found it, I must use "libc.so.6" and the function name is strdup not _strdup... So, it push to an other questions : Is libc.so.6 present on any linux distro ? (I use a fedora 13 here) Arnaud -------------------------------------------------- From: <arnaud.champion@devatom.fr> Sent: Tuesday, October 19, 2010 2:25 PM To: "Eric Blake" <eblake@redhat.com>; "Justin Clift" <jclift@redhat.com> Cc: <libvir-list@redhat.com> Subject: Re: [libvirt] libvirt library binary name for linux
?I have tried libc.so and it doesn't contains _strdup, amybe it's strdup instead I will try. Anyway I have a little question (a windowsian question :) ). Under windows I have a tool named "depends.exe" with it, I can sse what is exposed thru a dll, is there any equivalent under linux ?
Arnaud
-------------------------------------------------- From: "Eric Blake" <eblake@redhat.com> Sent: Tuesday, October 19, 2010 2:15 PM To: "Justin Clift" <jclift@redhat.com> Cc: <libvir-list@redhat.com> Subject: Re: [libvirt] libvirt library binary name for linux
On 10/19/2010 06:07 AM, Justin Clift wrote:
I'm not sure which library file the code is in though. For most things it's not needed.
glibc (that is, libc.so, which is pretty much universally linked in to every other program already). You don't need to add -lc to your compiler line, at any rate.
-- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 10/19/2010 11:31 PM, arnaud.champion@devatom.fr wrote:
?Okay, I have found it, I must use "libc.so.6" and the function name is strdup not _strdup...
So, it push to an other questions :
Is libc.so.6 present on any linux distro ? (I use a fedora 13 here)
It's a very standard library. Sometimes it is "libc.so.6", on older Linux's, it can be "libc.so.5". You are generally safe to use it. :)

On Tue, Oct 19, 2010 at 14:57, Justin Clift <jclift@redhat.com> wrote:
On 10/19/2010 11:31 PM, arnaud.champion@devatom.fr wrote:
?Okay, I have found it, I must use "libc.so.6" and the function name is strdup not _strdup...
So, it push to an other questions :
Is libc.so.6 present on any linux distro ? (I use a fedora 13 here)
It's a very standard library. Sometimes it is "libc.so.6", on older Linux's, it can be "libc.so.5".
You are generally safe to use it. :)
why does he need to know it? It only helps to ruin portability.

On 10/20/2010 12:03 AM, Alejandro Mery wrote: <snip>
It's a very standard library. Sometimes it is "libc.so.6", on older Linux's, it can be "libc.so.5".
You are generally safe to use it. :)
why does he need to know it? It only helps to ruin portability.
Heh. At a guess, Arnaud is looking like he's in very early stages of learning Linux development. So, he's probably not exactly sure what he does or doesn't need to know, and is doing his best with the knowledge he has. :)

Yes I know that it is not good for portability and I plan to remove the use of strdup (and libc) by using custom marshaling, I was just making a test. -------------------------------------------------- From: "Justin Clift" <jclift@redhat.com> Sent: Tuesday, October 19, 2010 3:11 PM To: "Alejandro Mery" <amery@geeks.cl> Cc: <arnaud.champion@devatom.fr>; <libvir-list@redhat.com> Subject: Re: [libvirt] libvirt library binary name for linux
On 10/20/2010 12:03 AM, Alejandro Mery wrote: <snip>
It's a very standard library. Sometimes it is "libc.so.6", on older Linux's, it can be "libc.so.5".
You are generally safe to use it. :)
why does he need to know it? It only helps to ruin portability.
Heh. At a guess, Arnaud is looking like he's in very early stages of learning Linux development. So, he's probably not exactly sure what he does or doesn't need to know, and is doing his best with the knowledge he has. :)

?Ok, good news -------------------------------------------------- From: "Justin Clift" <jclift@redhat.com> Sent: Tuesday, October 19, 2010 2:57 PM To: <arnaud.champion@devatom.fr> Cc: "Eric Blake" <eblake@redhat.com>; <libvir-list@redhat.com> Subject: Re: [libvirt] libvirt library binary name for linux
On 10/19/2010 11:31 PM, arnaud.champion@devatom.fr wrote:
?Okay, I have found it, I must use "libc.so.6" and the function name is strdup not _strdup...
So, it push to an other questions :
Is libc.so.6 present on any linux distro ? (I use a fedora 13 here)
It's a very standard library. Sometimes it is "libc.so.6", on older Linux's, it can be "libc.so.5".
You are generally safe to use it. :)

[Would you mind changing your style to avoid top-posting?] On 10/19/2010 06:31 AM, arnaud.champion@devatom.fr wrote:
?Okay, I have found it, I must use "libc.so.6" and the function name is strdup not _strdup...
Windows prefixes all system functions with _, Linux does not. strdup() is required by POSIX 2008 but not C99. Windows libc has the notorious habit of providing only what is required by C89 (not even C99); which means MSVCRT might not have strdup by default. However, I do know that mingw provides strdup(); maybe there's a difference between what mingw and native microsoft tools provide.
So, it push to an other questions :
Is libc.so.6 present on any linux distro ? (I use a fedora 13 here)
Libc is present on EVERY system, Linux or otherwise; otherwise, you wouldn't be able to run C programs. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 10/19/2010 11:25 PM, arnaud.champion@devatom.fr wrote:
?I have tried libc.so and it doesn't contains _strdup, amybe it's strdup instead I will try. Anyway I have a little question (a windowsian question :) ). Under windows I have a tool named "depends.exe" with it, I can sse what is exposed thru a dll, is there any equivalent under linux ?
Hmmm, two tools might be useful, but I don't personally know them in much depth: + ldd + nm ldd can be used on an executable file, to show which dynamic libraries that file needs. For example, if I have the program "/bin/bash": $ ldd /bin/bash linux-vdso.so.1 => (0x00007fff999ff000) libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00000030cd600000) libdl.so.2 => /lib64/libdl.so.2 (0x00000030bc200000) libc.so.6 => /lib64/libc.so.6 (0x00000030bba00000) /lib64/ld-linux-x86-64.so.2 (0x00000030bb600000) The "nm" program, can be used on a dynamic library to show which symbols it provides. For example, on /lib64/libc.so.6: $ nm /lib64/libc.so.6 <snip> 00000030bbd7ba60 B __daylight 00000030bba2c550 T __dcgettext 00000030bba2c550 t __dcgettext_internal 00000030bba2d5e0 t __dcigettext 00000030bba2dfc0 t __dcngettext 00000030bba7c600 T __default_morecore 00000030bba33140 t __default_sigpause 00000030bba2c560 T __dgettext 00000030bba95be0 t __difftime 00000030bbb1e7c0 t __dl_iterate_phdr 00000030bba2dfd0 t __dngettext 00000030bba4f150 t __dprintf <snip - it is a long list> Both nm and ldd can be given options, which change what they display. Looking at the questions you are asking, they are a bit unusual. There is nothing _wrong_ with your questions, but they make me curious what you are trying to do. If you are ok to explain the idea you are trying, we might know of a better or easier way. (no guarantees though!) :) Regards and best wishes, Justin Clift
Arnaud

?Well, as I have said I work on .Net/Mono bindings. To make bindings, we use largely the marshaling methods of .Net/Mono. I was working on bindings virConnectOpenAuth, so I have de marshal virConnectCredential struct, these kind of thing. Matthias Bolte help me a lot to make all the process thru callback working. And we have discover that the virConnectCredential was reseted by the marshaling process (in particular marshaling process free the result member of the virConnectCredential, and in fact, for libvirt, it's the driver responsability to free the result member). So Matthias suggest me to bind strdup to .Net and use it to be sure that the result member is not freed by marshaling. And it works. I know, it is not very elegant, and right now I'm working on another possible solution thru custom marshaling (I hope it will work). Anyway, As I plan to make bindings works for Mono and .Net, I have made some tests with Mono/Windows Mono/Linux and .Net/Windows. And all seems to work fine, I have made a sample application that connect to a ESX hypervisor and list domains and it works fine, thanks for your help. As you can see, I'm not a linux expert, and ldd and nm tools can help me to find things, so thanks for these infos. Arnaud PS : really sorry for my english, I hope I'm clear let me know anyway -------------------------------------------------- From: "Justin Clift" <jclift@redhat.com> Sent: Tuesday, October 19, 2010 2:53 PM To: <arnaud.champion@devatom.fr> Cc: "Eric Blake" <eblake@redhat.com>; <libvir-list@redhat.com> Subject: Re: [libvirt] libvirt library binary name for linux
On 10/19/2010 11:25 PM, arnaud.champion@devatom.fr wrote:
?I have tried libc.so and it doesn't contains _strdup, amybe it's strdup instead I will try. Anyway I have a little question (a windowsian question :) ). Under windows I have a tool named "depends.exe" with it, I can sse what is exposed thru a dll, is there any equivalent under linux ?
Hmmm, two tools might be useful, but I don't personally know them in much depth:
+ ldd + nm
ldd can be used on an executable file, to show which dynamic libraries that file needs. For example, if I have the program "/bin/bash":
$ ldd /bin/bash linux-vdso.so.1 => (0x00007fff999ff000) libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00000030cd600000) libdl.so.2 => /lib64/libdl.so.2 (0x00000030bc200000) libc.so.6 => /lib64/libc.so.6 (0x00000030bba00000) /lib64/ld-linux-x86-64.so.2 (0x00000030bb600000)
The "nm" program, can be used on a dynamic library to show which symbols it provides. For example, on /lib64/libc.so.6:
$ nm /lib64/libc.so.6 <snip> 00000030bbd7ba60 B __daylight 00000030bba2c550 T __dcgettext 00000030bba2c550 t __dcgettext_internal 00000030bba2d5e0 t __dcigettext 00000030bba2dfc0 t __dcngettext 00000030bba7c600 T __default_morecore 00000030bba33140 t __default_sigpause 00000030bba2c560 T __dgettext 00000030bba95be0 t __difftime 00000030bbb1e7c0 t __dl_iterate_phdr 00000030bba2dfd0 t __dngettext 00000030bba4f150 t __dprintf <snip - it is a long list>
Both nm and ldd can be given options, which change what they display.
Looking at the questions you are asking, they are a bit unusual.
There is nothing _wrong_ with your questions, but they make me curious what you are trying to do. If you are ok to explain the idea you are trying, we might know of a better or easier way. (no guarantees though!) :)
Regards and best wishes,
Justin Clift
Arnaud

On 10/19/2010 07:13 AM, arnaud.champion@devatom.fr wrote:
?Well, as I have said I work on .Net/Mono bindings.
To make bindings, we use largely the marshaling methods of .Net/Mono. I was working on bindings virConnectOpenAuth, so I have de marshal virConnectCredential struct, these kind of thing. Matthias Bolte help me a lot to make all the process thru callback working. And we have discover that the virConnectCredential was reseted by the marshaling process (in particular marshaling process free the result member of the virConnectCredential, and in fact, for libvirt, it's the driver responsability to free the result member). So Matthias suggest me to bind strdup to .Net and use it to be sure that the result member is not freed by marshaling. And it works.
strdup() is nothing more than malloc() followed by strcpy(); it is such a fundamental operation to copy strings into newly allocated memory that I'm surprised that you don't know how to do that natively in C# without having to bind in strdup() in the first place (even if you do have to do it in two phases of allocation and copying rather than as a single function call). -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2010/10/19 Eric Blake <eblake@redhat.com>:
On 10/19/2010 07:13 AM, arnaud.champion@devatom.fr wrote:
?Well, as I have said I work on .Net/Mono bindings.
To make bindings, we use largely the marshaling methods of .Net/Mono. I was working on bindings virConnectOpenAuth, so I have de marshal virConnectCredential struct, these kind of thing. Matthias Bolte help me a lot to make all the process thru callback working. And we have discover that the virConnectCredential was reseted by the marshaling process (in particular marshaling process free the result member of the virConnectCredential, and in fact, for libvirt, it's the driver responsability to free the result member). So Matthias suggest me to bind strdup to .Net and use it to be sure that the result member is not freed by marshaling. And it works.
strdup() is nothing more than malloc() followed by strcpy(); it is such a fundamental operation to copy strings into newly allocated memory that I'm surprised that you don't know how to do that natively in C# without having to bind in strdup() in the first place (even if you do have to do it in two phases of allocation and copying rather than as a single function call).
The problem is to get the result into unmanaged memory on the correct heap. The ownership of cred.result is transferred to the driver that calls free() on it when done. Therefore, you cannot pass a pointer to the data of a managed string from C# to the libvirt driver, because that creates a double/invalid-free. C# provides Marshal.StringToHGlobalAuto() that created a copy of a string in memory allocated using GlobalAlloc() from the WinAPI. The docs emphasis that this copy must be freed using GlobalFree() that might be incompatible with free(), I'm not sure. Because of that I suggested to do a strdup() of the result from Marshal.StringToHGlobalAuto() to make sure cred.result can be freed using free(). See [1] for more details. When I understood Arnaud correctly then passing the result of Marshal.StringToHGlobalAuto() directly as cred.result didn't work, but passing the result from strdup() works. The sole purpose of all this is just to get cred.result allocated in unmanaged memory that can be freed using free(). Marshal.StringToHGlobalAuto() + strdup() just works for now but is ugly. Arnaud said that he is working on a better approach for this (custom marshaling), that doesn't require strdup(). [1] https://www.redhat.com/archives/libvir-list/2010-October/msg00525.html Matthias

On 10/19/2010 08:23 AM, Matthias Bolte wrote:
strdup() is nothing more than malloc() followed by strcpy();
See [1] for more details. When I understood Arnaud correctly then passing the result of Marshal.StringToHGlobalAuto() directly as cred.result didn't work, but passing the result from strdup() works.
Thanks for the reminder. I'm not very familiar with C# myself, but I do agree with the analysis that Windows memory management is not always straight-forward, since there is more than just the malloc() pool, and therefore strdup() is not necessarily a trivial operation since it determines which memory pool is in use. Sorry if my previous message came across harsher than intended (now that I've gone back and re-read it).
Marshal.StringToHGlobalAuto() + strdup() just works for now but is ugly. Arnaud said that he is working on a better approach for this (custom marshaling), that doesn't require strdup().
Good luck with it, and thanks again to Arnaud for taking on the task of a new language binding. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (5)
-
Alejandro Mery
-
arnaud.champion@devatom.fr
-
Eric Blake
-
Justin Clift
-
Matthias Bolte