LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2018, 07:24 AM   #1
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 130

Rep: Reputation: 2
error: ld returned 1 exit status


sub :- error: ld returned 1 exit status

hi to all, I've centos7.5 and codeblocks17.12 in VM. I am building a simple shared library file. but having following problem:-

header file:-
-------------
singlyll.h

Code:
#ifndef SINGLYLL_H_INCLUDED
#define SINGLYLL_H_INCLUDED

#include <iostream>
#include <cstdlib>

class  linklist
{
    struct node
    {
        int data;
        node *link;
    };

    node *start, *p;


public:

void display( linklist * pll );
};

#endif // SINGLYLL_H_INCLUDED
implementation file :-
---------------------
singlyll.cpp

Code:
#include "singlyll.h"

using namespace std;

void linklist::display(  linklist *pll)
{
    if(pll->start == NULL)
    {
        cout << "list is empty\n";

        return;
    }

    cout << "List : ";

    node *p = pll->start;

    for(; p != NULL; p = p->link)
    {
        cout << p->data <<"\t";
    }
    cout <<"\n\n";
}


build message :-
Code:
error: ld returned 1 exit status
-------------- Build: Debug in singlyll (compiler: GNU GCC Compiler)---------------
Code:
g++ -shared  obj/Debug/singlyll.o  -o bin/Debug/libsinglyll.so  
/usr/bin/ld: obj/Debug/singlyll.o: relocation R_X86_64_32 against `.rodata' 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), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
Old 09-08-2018, 07:58 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
your second line gives you a BIG Clue
Code:
/usr/bin/ld: obj/Debug/singlyll.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
your linking is wrong. look at the tail end of that clue.

vector why not use that instead. just an idea.

Last edited by BW-userx; 09-08-2018 at 08:36 AM.
 
1 members found this post helpful.
Old 09-09-2018, 12:16 AM   #3
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 130

Original Poster
Rep: Reputation: 2
i didn't get your point. please tell me how to do it in CodeBlocks.

Quote:
your second line gives you a BIG Clue
Code:
Code:
/usr/bin/ld: obj/Debug/singlyll.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

Last edited by rahulvishwakarma; 09-09-2018 at 12:18 AM.
 
Old 09-09-2018, 03:56 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,150

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
Compiler Settings
Other Options
add this: -fPIC
 
Old 09-11-2018, 07:53 AM   #5
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 130

Original Poster
Rep: Reputation: 2
Thanks for reply. I did it like this :-
Click image for larger version

Name:	fPIC.png
Views:	163
Size:	227.0 KB
ID:	28574

but having same problem.
 
Old 09-11-2018, 08:23 AM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
what are you doing exactly? I did this,
link.h
Code:
#ifndef LINKKY_H_INCLUDED
#define LINKKY_H_INCLUDED

struct node
  {
    int data;
    node *next;
  };

class list
  {
    private:
    node *head, *tail;
    public:
    list()
    {
      head=NULL;
      tail=NULL;
    }
    void display(list * pll);
    void display();
  };



#endif // LINKKY_H_INCLUDED
link.cpp
Code:
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include "linkky.h"


using namespace std;

void list::display(  list *pll)
{
    if(pll->head == NULL)
    {
        cout << "list is empty\n";

        return;
    }

    cout << "List : ";

    node *p = pll->head;

    for(; p != NULL; p = p->next)
    {
        cout << p->data <<"\t";
    }
    cout <<"\n\n";
}

void list::display()
  {
    node *temp=new node;
    temp=head;
    while(temp!=NULL)
    {
      cout<<temp->data<<"\t";
      temp=temp->next;
    }
  }
in codeblocks under settings->compiler-> I selected follow c++ 14 and it compiles without error.

i found this on a very similar error you're getting.

https://stackoverflow.com/questions/...str1-8-can-not

Last edited by BW-userx; 09-11-2018 at 08:34 AM.
 
Old 09-11-2018, 08:32 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,150

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
You might want to do a 'Build All' or 'Rebuild' or 'Clean and Build' or anyhow it is called.
 
1 members found this post helpful.
Old 09-12-2018, 06:35 AM   #8
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 130

Original Poster
Rep: Reputation: 2
thank you very much friend,. I did as you told and I got solution.
 
  


Reply

Tags
c++, codeblocks


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] collect2: error: ld returned 1 exit status shogun1234 Programming 4 05-30-2019 01:09 PM
Error: ld returned 1 exit status przi Linux - Software 2 01-06-2016 12:53 PM
[SOLVED] glibc 6.9.1 make error - ld returned 1 exit status JulianD Linux From Scratch 5 01-29-2015 01:23 AM
Error Message : collect2: ld returned 1 exit status biplabbijay Programming 1 11-26-2009 05:46 PM
Error: collect 2: ld returned 1 exit status Rituparna Linux - Software 11 06-25-2009 02:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration