hi to all
i've centos 6.6 and codeblocks 16.01. i want to build shared object library file. I chosed as
new->project->shared library, then language c then project title as "int_valid". now i gave following code in ( under project int_valid )
intvalidation.c
----------------
#include "intvalidation.h"
int intvalidation(const char * iint)
{
int i = 0, count = 0, len;
//unsigned long long int num = 0;
char * strnum = 0, chnum = 0;
strnum = (char *) malloc(sizeof (20));
//sprintf(strnum, "%d", iint);
len = strlen(iint);
printf(" len = %d ", len);
for( count = 0; count < len; count++)
{
chnum = (*(iint + count )) ;
i = chnum - 48;
if( i >= 0 && i <= 9 )
continue;
else
{
// printf("\n number is not valid \n");
return 0;
}
}
return 1;
}
in intvalidation.h
-------------------
#ifndef INTVALIDATION_H
#define INTVALIDATION_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int intvalidation(const char * iint);
#endif
in man.c file of second project :-
----------------------------------
#include <stdio.h>
#include <stdlib.h>
int intvalidation(char *iint);
int AddInt(int i1, int i2);
int main()
{
unsigned int x, y, sum = 0;
char *num1, *num2;
num1 = (char *)malloc(6);
printf("\n Enter number x = ");
scanf("%s", num1);
if(!intvalidation(num1))
{
printf("\n number %s is invalid \n", num1);
exit(1);
}
x = atoi(num1);
num2 = (char*) malloc(6);
printf( "\n Enter number to add: ");
scanf("%s", num2);
if(!intvalidation(num2))
{
printf("\n number %s is invalid \n", num2);
exit(1);
}
y = atoi(num2);
//sum = x + y;
sum = AddInt(x, y);
printf("\n %d + %d = %d", x, y, sum);
return 0;
}
in this project i want ot check validity of intger and making a shared library file for this
validation
now when i compile first project ( int_valid project having file file intvalidatoin.c and
intvalidatoin.h)
this generates sharedfile as :-
"liblibint_vaild.so"
why it is having two "lib" not a single one lib.
and second thing that how to link library file in our project.
now when i compile first project ( int_valid project having file file intvalidatoin.c and
intvalidatoin.h)
this generates sharedfile as :-
"liblibint_vaild.so"
Look into Project->Properties->Build targets->Output filename
If there is written "libint_vaild" remove the first "lib", or uncheck the option "Auto-generate filename prefix" i don't know why this is done...
and second thing that how to link library file in our project.
1) use the include file of the library so you don't have to forward declare the functions.
by this use
#include "intvalidation.h"
in min.c and add the include path to the project by
Project->Build options->select the project name on the left->Search directories->Compiler->add: add the path to the "intvalidation.h" file
2) now you have to add the library and the library path:
Project->Build options->select the project name on the left->Search directories->Linker->add: add the path to the "libint_vaild.so" file
for the library:
Project->Build options->select the project name on the left->Linker settings->Add: add "libint_vaild" Ok
now all should work... (maybe you have to add the ".so" to the library, but i am no sure)