hi to all , I've centos 7.5 in VM. I m trying to compile a shared library file. But hanging up with message:-
-------------- Build: Release in singlyll (compiler: GNU GCC Compiler)---------------
gcc -Wall -O2 -c "/opt/projects/code blocks/data structures/linkedlist/soproject/singlyll/singlyll/singlyll.c" -o obj/Release/singlyll.o
g++ -shared obj/Release/singlyll.o -o bin/Release/liblibsinglyll.so -s
/usr/bin/ld: obj/Release/singlyll.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))
||=== Build: Release in singlyll (compiler: GNU GCC Compiler) ===|
error: ld returned 1 exit status
singlyll.h :-
--------------
#ifndef SINGLYLL_H_INCLUDED
#define SINGLYLL_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node * link;
}node;
node *start, *p;
void display( struct node * start);
void search( struct node *start, int data);
struct node * addatbegin( struct node *start, int data);
struct node * addatend( struct node*start, int data);
struct node * addafter( struct node * start, int data, int item);
struct node * addberfore( struct node * start, int data, int item);
struct node * createlist( struct node * start, int n);
struct node * del( struct node* start, int data);
struct node * reverse( struct node *start);
#endif // SINGLYLL_H_INCLUDED
singlyll.c :-
--------------
#include "singlyll.h"
//struct
//{
// int data;
// struct node * link;
//}node;
void display(struct node* start)
{
struct node *p;
if(start == NULL)
{
printf("list is empty\n");
return;
}
printf("List : ");
for(p = start; p != NULL; p = p->link)
{
printf("%d \t", p->data);
}
printf("\n\n");
}
void search(struct node* start, int item)
{
struct node* p = start;
int pos = 1;
for(;p != NULL; p = p->link)
{
if(p->data == item )
{
printf( "item %d found at position %d \n", item, pos);
}
pos++;
}
printf("item %d not found in list\n", item);
}
struct node* addatbegin( struct node* start, int item)
{
struct node*temp = (struct node*) malloc(sizeof(node));
temp->data = item;
temp->link = start;
start = temp;
return start;
}
struct node* addatend(struct node* start, int item)
{
struct node* p = start;
struct node* temp = start;
temp = (struct node*) malloc(sizeof(node));
temp->link = NULL;
while(p->link!= NULL)
p = p->link;
p->link = temp;
return start;
}
struct node* addafter(struct node* start, int item, int data)
{
struct node*p = start, *temp;
while( p != NULL)
{
if(p->data == item)
{
temp = (node*) malloc(sizeof(node));
temp->data = item;
temp->link = p->link;
p->link = temp;
return start;
}
p = p->link;
}
printf(" not present in the list\n");
return start;
}
struct node* addberfore(struct node* start, int data, int item)
{
struct node*temp, *p;
if(start == NULL)
{
printf("list is empty\n");
return start;
}
/*insert before the first struct node*/
if(item == start->data)
{
temp = (node*) malloc(sizeof(node));
temp->data = data;
temp->link = start;
start = temp;
}
p = start;
while(p->link != NULL)
{
if(p->link->data == item)
{
temp = (node*)malloc(sizeof(node));
temp->data = data;
temp->link = p->link;
p->link = temp->link;
return start;
}
p = p->link;
}
printf("%d not present in the list\n", item);
return start;
}
struct node* createlist(struct node* start, int n)
{
int i, data;
start = NULL;
if( n == 0)
{
return start;
}
printf("Enter elements to be inserted : ");
scanf("%d", &data);
start = addatbegin(start, data);
for( i = 2; i <= n; i++ )
{
printf("Element to be inserted : ");
scanf("%d",&data);
start = addatend(start, data);
}
return start;
}
struct node* del(struct node* start, int data)
{
struct node*p, *temp;
if(start == NULL)
{
printf("The list is empty \n");
return start;
}
if(start->data == data)
{
temp= start;
start = start->link;
free(temp);
return start;
}
p = start;
while(p->link != NULL)
{
if( p->link->data == data)
{
temp = p->link;
p->link = temp->link;
free(temp);
return start;
}
p = p->link;
}
printf("Element %d not found\n", data);
return start;
}
struct node* reverse(struct node* start)
{
struct node*prev, *ptr, *next;
prev = NULL;
ptr = start;
while(ptr->link != NULL)
{
next = ptr->link;
ptr->link = prev;
prev = ptr;
ptr = next;
}
return start;
}
have any one solution for this. how to handle this "ld returned i exit status" problem.