Shared Library, common function

Shared Library, common function

Post by Peteris Krumin » Thu, 03 Jul 2003 04:14:48



Hello,

 I have created a shared library, so any tool within project shared most
commonly used functions.

 One of the functions looks like this:

FILE *db_fifo() {
    FILE *fifo;

    fifo = fopen("/somewhere/db","w");
    if (fifo)
        return fifo;

    return NULL;

Quote:}

 unfortunately after the function returns, nobody is able to use the fifo,
because it is invalid.

 Is it possible to use a shared libarary and return usable resources like a
pointer to FILE?

P.Krumins

 
 
 

Shared Library, common function

Post by Barry Margoli » Thu, 03 Jul 2003 05:27:48




Quote:>Hello,

> I have created a shared library, so any tool within project shared most
>commonly used functions.

> One of the functions looks like this:

>FILE *db_fifo() {
>    FILE *fifo;

>    fifo = fopen("/somewhere/db","w");
>    if (fifo)
>        return fifo;

>    return NULL;
>}

> unfortunately after the function returns, nobody is able to use the fifo,
>because it is invalid.

> Is it possible to use a shared libarary and return usable resources like a
>pointer to FILE?

Of course it is.  fopen() is also in a shared library, and it returns a
pointer to FILE that's usable.

There must be something else wrong with your code.

--

Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Shared Library, common function

Post by Chuck Dillo » Fri, 04 Jul 2003 23:30:00



>  Is it possible to use a shared libarary and return usable resources like a
> pointer to FILE?

Sure.  What system are you using?  If you are in a pseudo-UNIX
environment (i.e. cygwin, u/win...) under ms-windows this can be a big
issue.

-- ced

--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.

 
 
 

Shared Library, common function

Post by Peteris Krumin » Mon, 07 Jul 2003 05:05:49





>>  Is it possible to use a shared libarary and return usable resources
>>  like a
>> pointer to FILE?

> Sure.  What system are you using?  If you are in a pseudo-UNIX
> environment (i.e. cygwin, u/win...) under ms-windows this can be a big
> issue.

Thanks for the comment, i have already solved the problem, as my function
the library was more compicated than i posted, i didnt notice a small bug
which affected the pointer to be returned.
And, i am not programming in a pseudo-unix env.

P.Krumins

 
 
 

1. FORTRAN common in AIX shared library not shared at runtime (0/1)

We got following problem in accessing a FORTRAN Common within a
shared library.

The task is to put an FORTRAN common in a shared library and access
this common from:

a) routines which resides inside the shared library
b) routines statically linked to an executable which uses the shared
   library at runtime

At link time of the shared library we use the -bE: -bM:SRE and
-bnoentry flags. The export list used with the -bE: flag contains
the FORTRAN common to be shared. The problem at runtime is, it seems
as if the FORTRAN common is not shared between the routines in the
shared library and the routines in the executable.

I add an (already shortened) example which demonstrates the problem.
The example exists of:
                                              source        location
--------------------------------------------------------------------
FORTRAN common SLCOM                          sl_common.inc       SL
FORTRAN routine SL_BLOCKDATA initial. SLCOM   sl_blockdata.f      SL
FORTRAN routine PRINT_COM printing SLCOM      print_com.f         SL
C global variables STRING, STRUKTUR           sl_globals.h        SL
C routine print_glob printing C globals       print_glob.c        SL
FORTRAN routine PRINT_COM_LOC printing SLCOM  print_com_loc.f    EXE
C routine print_glob_loc printing C globals   print_glob_loc.c   EXE
C main() routine                              main.c             EXE

The main() routine just prints the contents of the FORTRAN common
and C globals via the corresponding shared library and "local"
print_XXX() routines. The resulting output demonstrates, that the C
globals are shared and the FORTRAN common is duplicated (watch the
printed memory addresses).

Has anybody else experienced this problem and solved it? We are
running AIX 4.1 on an IBM RS600 40S system.

Thanx Guenter.

P.S. Source code of the mentioned example is attached. You only have
to save all files in one directory and call make.

2. Socket Programming in Perl

3. Common pitfalls for C++ shared libraries?

4. my SMTP host used for e-mail cloaking?

5. f77 common blocks and shared libraries

6. FormMail.pl

7. Importing COMMON blocks into shared libraries

8. Help!! How to Pass Variables to my cgi...

9. Will strip(debug shared library) == nodebug shared library ?

10. Help with building shared libraries with dependencies on other shared libraries

11. Question: Inclusion of shared libraries during linking of shared libraries

12. Shared library loading shared library.

13. Need a Shared Library Guru: beyond simple shared library question