LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-23-2018, 06:42 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
-fPIC switch has stopped working?


Hi All,
I just upgraded to a new PC that I need to use use ubuntu 17 on ( graphics drivers )

I've went to compile some code that's always worked, it links against an external .o file ( not my file ), however I now get a liking error and am told to use -fPIC. However I use fPIC in my makefile
Code:
CC   =$(TRGT)g++ -fPIC -std=c++0x
CP   = $(TRGT)objcopy
AS   = $(TRGT)gcc -x assembler-with-cpp
the error is
Code:
iodriver_x64.o: relocation R_X86_64_32S against `.rodata' cannot 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
Is there some error with fPIC now? "gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2)" Does anyone know a way I can fix this? Thanks
 
Old 03-23-2018, 08:36 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
You should find the line in the compilation-log (hopefully you do have one) which created the object module. For some reason it was compiled without -fPIC (Most likely it wasn't compiled with recent gcc/g++ as they use -fPIC by default on x86_64 platform.)

Note: usually, CC is the C-compiler, CXX is the C++-compiler.

Last edited by NevemTeve; 03-23-2018 at 08:41 AM.
 
1 members found this post helpful.
Old 03-23-2018, 10:22 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
So it’s the object file the needs -fPIC not my end? If so I’ll have to get onto them.
Thanks
 
Old 03-23-2018, 11:59 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
For example:
Code:
clang -o whatnot.o -c whatnot.c   # doesn't default option -fPIC
gcc   -o whatnot      whatnot.o   # defaults option -pie ==> fail
 
1 members found this post helpful.
Old 03-23-2018, 12:38 PM   #5
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
Sorry I didn't make myself clear. By object file I mean the one provided by the io board manufacturer? I have my code .c and compile in their .o. What I was asking is it them when they compile the .o file who need to use -fPIC. Do I need to contact them and ask them to provide the .o after they have compiled with -fPIC? Thanks
 
Old 03-23-2018, 01:58 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
The error message states that 'iodriver_x64.o' was compiled without '-fPIC'
You cannot create shared library or relocatable executable from it, but you still can create 'plain old' executable with gcc-linker-option '-no-pie'

Example:
Code:
clang -o whatnot.o    -c whatnot.c
gcc   -o whatnot -no-pie whatnot.o

Last edited by NevemTeve; 03-23-2018 at 02:01 PM.
 
1 members found this post helpful.
Old 03-23-2018, 02:28 PM   #7
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
Ahh right thanks
 
  


Reply



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
Nagios web interface stopped working afer I got postfix working erosbach Linux - Newbie 1 03-27-2017 02:39 PM
$ startx stopped working, was working fine when I shut it down last night BogoMIPS_1962 Slackware 2 08-10-2013 01:04 PM
[SOLVED] Ubuntu 11.04 mic stopped working in HP G-32, but was working before.how to fix it? Highjo Ubuntu 4 08-08-2011 05:59 AM
Error recompile with fPIC, but fPIC is already as a compilation option eolmsan Linux - Software 4 12-03-2008 11:05 AM
about -fpic/-fPIC option for gcc George2 Programming 2 09-04-2006 01:38 AM

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

All times are GMT -5. The time now is 02:07 AM.

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