HOW CAN ADD OUR FUNCTION IN LIBRARY.

Answers were Sorted based on User's Feedback



HOW CAN ADD OUR FUNCTION IN LIBRARY...

Answer / vignesh1988i

it's simple.....

just have ur function definition in one Cpp or C file.....ie save it as .cpp or .C file....
then include the file as #include "program.c"
and then wherever you need call that functionin an another program...
for example:
let me add my own ADDITION function in my library.....

this is my first file stored in .C....
int add(int a,int b)
{
int c;
c=a+b;
return c;
}
the file name for the above is add.c

then am opening my main program file in .c mode ....
#include<stdio.h>
#include<conio.h>
#include"add.c"
void main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=add(a,b);
printf("\n the added sum is :%d",c);
getch();
}



thank u

Is This Answer Correct ?    40 Yes 29 No

HOW CAN ADD OUR FUNCTION IN LIBRARY...

Answer / ataraxic

Using ar utility.
Let's say we have lib1.c lib2.c and myprog.c
We want to do a library from lib1.c && lib2.c, and compile
myprog.c with this library afterwards.
The steps are:
Compile
1. gcc -c lib1.c -o lib1.o
2. gcc -c lib2.c -o lib2.o

Create archive named libmy.a
3. ar -rcsv libmy.a lib1.o lib2.o

Compile myprog with newly created lib
4. gcc myprog.c -L. -lmy -o myprog

Is This Answer Correct ?    3 Yes 4 No

HOW CAN ADD OUR FUNCTION IN LIBRARY...

Answer / raje

just have ur function definition in one Cpp or C
file.....ie save it as .cpp or .C file....
then include the file as #include "program.c"
and then wherever you need call that functionin an another
program...
for example:
let me add my own ADDITION function in my library.....

this is my first file stored in .C....
int add(int a,int b)
{
int c;
c=a+b;
return c;
}
the file name for the above is add.c

then am opening my main program file in .c mode ....
#include<stdio.h>
#include<conio.h>
#include"add.c"
void main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=add(a,b);
printf("\n the added sum is :%d",c);
getch();
}

Is This Answer Correct ?    10 Yes 12 No

HOW CAN ADD OUR FUNCTION IN LIBRARY...

Answer / ravi joshi

Do you mean funtion(s) in libc? if not, it is very simple.
Irrespective or static or dynamic, the library always
contains an executable code but not linked. When application
uses the library, the code is linked at application link
time or load time depending on whether the library is static
or dynamic respectively.

for adding function in a library, just add the new function
as if you are adding any other function and recompile it as
a library. When linked with application, the new function
will become useable.

Is This Answer Correct ?    1 Yes 8 No

HOW CAN ADD OUR FUNCTION IN LIBRARY...

Answer / vivek

By library its generally meant an executable library. In
which case one can write a wrapper for the existinig DLL.
This will ofcourse require one to know the function
prototype of all exported functions.

If its a static library then simple write another lib and
add the existing one of the libs to link against.

Is This Answer Correct ?    2 Yes 16 No

Post New Answer

More C Interview Questions

Explain what is output redirection?

0 Answers  


What is static memory allocation?

0 Answers  


A.C func() { pritnf(" in fuction %d",MACRO); } MAIN.c testfunc() { #define MACRO 10 printf("in test function %d", MACRO); } main() { printf("in main %d",MACRO); func(); testfunc(); getch(); }

2 Answers   Wipro,


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

0 Answers   RBI,


can any one provide me the notes of data structure for ignou cs-62 paper

0 Answers   Ignou,






How can I automatically locate a programs configuration files in the same directory as the executable?

0 Answers  


What is the purpose of main( ) in c language?

0 Answers  


How is pointer initialized in c?

0 Answers  


a number whose only prime factors are 2,3,5, and 7 is call humble number,,write a program to find and display the nth element in this sequence.. sample input : 2,3,4,11,12,13, and 100.. sample output : the 2nd humble number is 2,the 3rd humble number is 3,the 4th humble number is ,the 11th humble number is 12, the 12th humble number is 14, the 13th humble number is 15, the 100th humble number is 450.

0 Answers  


char *p="name"; printf(p);

1 Answers  


write a c program to find biggest of 3 number without relational operator?

12 Answers   TCS, Wipro,


Write a program for Overriding.

0 Answers  


Categories