<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamic loading of Shared Library problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877043#M703829</link>
    <description>The solution given by Cyrille to use extern "C"{} to avoid name mangling when compiled with aCC has worked for me. &lt;BR /&gt;---Thanks everybody.</description>
    <pubDate>Tue, 04 Jan 2005 07:13:20 GMT</pubDate>
    <dc:creator>Sujoy</dc:creator>
    <dc:date>2005-01-04T07:13:20Z</dc:date>
    <item>
      <title>Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877037#M703823</link>
      <description>Hi,&lt;BR /&gt;I am trying to create a shared libray in HP-UX which i intend to load dynamically using dlopen()/dlsym() calls.&lt;BR /&gt;&lt;BR /&gt;The library code is as follows: &lt;BR /&gt;===============================&lt;BR /&gt;bar.c&lt;BR /&gt;---------&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;&lt;BR /&gt;void gprint ()&lt;BR /&gt;{&lt;BR /&gt;fprintf ( stderr, "Hello, Shared World!\n" );&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;And the corresponding main is given as below:-&lt;BR /&gt;=============================================&lt;BR /&gt;foo.c&lt;BR /&gt;------&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;DLFCN.H&gt; &lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;void * handle = NULL; &lt;BR /&gt;void(*bar)(); // pointer to the gprint() //function in the shared lib&lt;BR /&gt;double (*cosine)(double);&lt;BR /&gt;char *error;&lt;BR /&gt;&lt;BR /&gt;handle = dlopen ( "./bar.so", RTLD_LAZY ); // open the shared lib&lt;BR /&gt;&lt;BR /&gt;// if the open failed, NULL was returned. Print the error code&lt;BR /&gt;if ( handle == NULL ) {&lt;BR /&gt;fprintf ( stderr, "fail 1: %s\n", dlerror() );&lt;BR /&gt;} &lt;BR /&gt;// the open succeeded, try and get the print() function from the shared lib&lt;BR /&gt;else {&lt;BR /&gt;fprintf ( stderr, "%x\n", handle );&lt;BR /&gt;bar = (void(*)())(dlsym ( handle, "gprint" ));&lt;BR /&gt;&lt;BR /&gt;// if bar is NULL, print() wasn't found in the lib, print error message&lt;BR /&gt;if ( bar == NULL ) {&lt;BR /&gt;fprintf ( stderr, "fail 2: %s\n", dlerror() );&lt;BR /&gt;} else {&lt;BR /&gt;&lt;BR /&gt;// print the address of the print() function, then call it&lt;BR /&gt;fprintf ( stderr, "%d\n", bar );&lt;BR /&gt;bar ( );&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;handle = dlopen ("/usr/lib/libm.sl", RTLD_LAZY);&lt;BR /&gt;if (!handle) {&lt;BR /&gt;fputs (dlerror(), stderr);&lt;BR /&gt;exit(1);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;cosine =(double (*)(double)) dlsym(handle, "cos");&lt;BR /&gt;if ((error = dlerror()) != NULL) {&lt;BR /&gt;fputs(error, stderr);&lt;BR /&gt;exit(1);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;printf ("%f\n", (*cosine)(90.0));&lt;BR /&gt;dlclose(handle);&lt;BR /&gt;&lt;BR /&gt;return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Here, i compiled bar.c as follows:&lt;BR /&gt;aCC +z -b bar.c -o bar.so&lt;BR /&gt;and foo.c as: -&lt;BR /&gt;aCC +z foo.c -o foo&lt;BR /&gt;&lt;BR /&gt;But when i try to run this as ./foo i see that &lt;BR /&gt;dlopen("./bar.so"), succeeds w/o error but when dlsym(handle,"gprint") called it returns NULL, and i see dlerror o/p as "Unresolved Symbol: gprint"&lt;BR /&gt;Ironically, the dlsym() call to cos() in /usr/lib/libm.sl succeeds w/o error. &lt;BR /&gt;&lt;BR /&gt;I am using 64 bit HP-UX 11i and my SHLIB_PATH includes the directory where bar.so is present.&lt;BR /&gt;&lt;BR /&gt;The "nm bar.so" o/p is given below:-&lt;BR /&gt;Symbols from bar.so:&lt;BR /&gt;&lt;BR /&gt;Name Value Scope Type Subspace&lt;BR /&gt;&lt;BR /&gt;$PIC$0 | 4808|static|code |$CODE$&lt;BR /&gt;C$3 | 4872|static|data |$LIT$&lt;BR /&gt;__StaticCtorTable_End|1073746024|static|data |$DATA$CDTORCEND$&lt;BR /&gt;__StaticCtorTable_Start|1073746008|static|data |$DATA$CDTORC1$&lt;BR /&gt;__iob | |undef |data |&lt;BR /&gt;__shlInit | |undef |code |&lt;BR /&gt;__shlInit | 4728|uext |stub |&lt;BR /&gt;__shlinit | -4|uext |stub |&lt;BR /&gt;__shlinit | |undef |code |&lt;BR /&gt;_shlInit | 4712|extern|entry |&lt;BR /&gt;_shlInit | 4744|extern|code |$CODE$&lt;BR /&gt;fprintf | |undef |code |&lt;BR /&gt;fprintf | 4792|uext |stub |&lt;BR /&gt;gprint__Fv | 4808|extern|entry |&lt;BR /&gt;gprint__Fv | 4808|extern|code |$CODE$&lt;BR /&gt;static___soa_bar_c_ |1073746008|static|data |$DATA$CDTORC1$&lt;BR /&gt;static___soa_shlInit_C_|1073746016|static|data |$DATA$CDTORC1$&lt;BR /&gt;&lt;BR /&gt;I am new to this dynamic loading, so any help will be very much appreciated. &lt;BR /&gt;&lt;BR /&gt;--Sujoy&lt;/DLFCN.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Mon, 27 Dec 2004 09:11:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877037#M703823</guid>
      <dc:creator>Sujoy</dc:creator>
      <dc:date>2004-12-27T09:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877038#M703824</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;your problem is a pure C++ name mangling pb.&lt;BR /&gt;Your usage of dl stuff seems good.&lt;BR /&gt;&lt;BR /&gt;Create a bar.h file like this&lt;BR /&gt;bar.h &lt;BR /&gt;----&lt;BR /&gt;extern "C" {&lt;BR /&gt;void gprint ();&lt;BR /&gt;}&lt;BR /&gt;----&lt;BR /&gt;&lt;BR /&gt;include it in your bar.c and that's it.&lt;BR /&gt;&lt;BR /&gt;++Cyrille</description>
      <pubDate>Tue, 28 Dec 2004 09:38:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877038#M703824</guid>
      <dc:creator>MAUCCI_2</dc:creator>
      <dc:date>2004-12-28T09:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877039#M703825</link>
      <description>Hi!&lt;BR /&gt;&lt;BR /&gt;Try  in compilation of this module to use&lt;BR /&gt;"-fpic" instead of "+z".&lt;BR /&gt;This work with gcc.&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Dec 2004 09:53:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877039#M703825</guid>
      <dc:creator>Stanimir</dc:creator>
      <dc:date>2004-12-28T09:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877040#M703826</link>
      <description>Have you tried compiling using +Z (i.e. uppercase Z, not lowercase z) ?&lt;BR /&gt;&lt;BR /&gt;Your code works without modification or an extra header file when compiled using gcc.</description>
      <pubDate>Tue, 04 Jan 2005 05:25:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877040#M703826</guid>
      <dc:creator>Stephen Keane</dc:creator>
      <dc:date>2005-01-04T05:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877041#M703827</link>
      <description>It is normal for this code to work with gcc, since gcc is a C compiler.&lt;BR /&gt;It also works as is with HPUX ANSIC cc compiler since it is also a C compiler.&lt;BR /&gt;&lt;BR /&gt;It doesn't work as is (and needs the modification I referred to in my initial post) because aCC is a C++ compiler and will mangle names.&lt;BR /&gt;&lt;BR /&gt;Try with g++ and it won't work until you modify the code as I said.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;BR&lt;BR /&gt;Cyrille</description>
      <pubDate>Tue, 04 Jan 2005 07:03:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877041#M703827</guid>
      <dc:creator>MAUCCI_2</dc:creator>
      <dc:date>2005-01-04T07:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877042#M703828</link>
      <description>Hi Cyrille,&lt;BR /&gt;Your earlier solution of extern "C"{} worked with aCC and served my purpose. &lt;BR /&gt;Thanks a lot. &lt;BR /&gt;--Sujoy</description>
      <pubDate>Tue, 04 Jan 2005 07:10:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877042#M703828</guid>
      <dc:creator>Sujoy</dc:creator>
      <dc:date>2005-01-04T07:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic loading of Shared Library problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877043#M703829</link>
      <description>The solution given by Cyrille to use extern "C"{} to avoid name mangling when compiled with aCC has worked for me. &lt;BR /&gt;---Thanks everybody.</description>
      <pubDate>Tue, 04 Jan 2005 07:13:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/dynamic-loading-of-shared-library-problem/m-p/4877043#M703829</guid>
      <dc:creator>Sujoy</dc:creator>
      <dc:date>2005-01-04T07:13:20Z</dc:date>
    </item>
  </channel>
</rss>

