HOW CAN ADD OUR FUNCTION IN LIBRARY.
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
What is external and internal variables What is dynamic memory allocation what is storage classes in C
What is the difference between scanf and fscanf?
#include<stdio.h> { printf("Hello"); } how compile time affects when we add additional header file <conio.h>.
what is difference between array and structure?
44 Answers College School Exams Tests, CTS, Google, HCL, IBM, Motorola, TCS,
There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.
24.what is a void pointer? 25.why arithmetic operation can’t be performed on a void pointer? 26.differentiate between const char *a; char *const a; and char const *a; 27.compare array with pointer? 28.what is a NULL pointer? 29.what does ‘segmentation violation’ mean? 30.what does ‘Bus Error’ mean? 31.Define function pointers? 32.How do you initialize function pointers? Give an example? 33.where can function pointers be used?
can anyone please tell about the nested interrupts?
program to find which character is occured more times in a string and how many times it has occured? for example in the sentence "i love india" the output should be i & 3.
How can I invoke another program or command and trap its output?
How would you rename a function in C?
how to find anagram without using string functions using only loops in c programming
formula to convert 2500mmh2o into m3/hr