Hello All,
 
This is regarding a query on linking libraries.
I would like to know whether anyone has faced
this problem.
 
I have a application, in which I open a file(test1),
and then I am calling a function defined in My library.
Inside this function I am trying open someother file
(test2) and then closing the file. While closing this
file(test2).. it errors out saying "Segmentation fault".
 
But this problem was not simulatable if close
fist file ( test1) before calling the function
in the library.
 
My test programs are here:
--------------------------
 
Application.c
 
void
main()
{
        FILE *appfd;
        appfd = fopen("test1","w");
        library();
        printf("Hello World\n");
}
 
Library.c
 
#include <stdio.h>
void
library() {
 
    FILE *f;
    f=fopen("test2","r");
   fclose(f);
}
 
 
I am doing following steps to build the library:
 
1. cc -c -o library.o library.c
2. ld -dn -G -Bstatic -o -libmylib.a library.o
3. cc -lmylib -o application application.c
4. ./application
 
Can any one tell me the root cause of this problem.
Or am I missing something.
 
 
Thanks in Advance,
Rajesh.
 

Reply via email to