Linked Questions
30 questions linked to/from GCC -fPIC option
1 vote
2 answers
1k views
Why shared library (.so) in Linux need to be compiled with -fPIC flag?
I'm a bit curious about the internal of ELF file. And I have this question: Why we need to compile a shared library (.so) with the flag -fPIC? While theoretically, we can dynamically link an ...
1 vote
1 answer
835 views
Why dynamic libraries source code should be compiled with position-independent code?
I'm very confused about position-independent code and its usage for dynamic libraries. I found this good example about -fPIC option of GCC: GCC -fPIC option and I figure out how it works. However, I'm ...
1 vote
1 answer
1k views
Plugin works in Linux Unity Editor but not in standalone Linux build
I have a very simple plugin from the code from this example (https://docs.unity3d.com/Manual/NativePlugins.html). I'm updating a UI Text Field with the value from the plugin. This works as expected ...
1 vote
3 answers
496 views
what is the benefit of storing virtual address in a pointer rather than physical address?
I have gone through below link and it says that on most Operating Systems , pointers store the virtual address rather than physical address but I am unable to get the benefit of storing virtual ...
1 vote
2 answers
1k views
Will an executable access shared-libraries' global variable via GOT?
I was learning dynamic linking recently and gave it a try: dynamic.c int global_variable = 10; int XOR(int a) { return global_variable; } test.c #include <stdio.h> extern int ...
1 vote
1 answer
1k views
Caffe error Ubuntu 16.04 with GPU /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/libglog.a
Hello I am using caffe using Ubuntu 16.04 using GPU anyone have idea how to solve this error I tried by cannot figure out how to remove it. Firstly getting errors of OpenCV and Protobuf and now that I ...
2 votes
2 answers
642 views
is g++ -fPIC applicable for executable too in addition to shared libraries?
I understand g++ -fPIC option as nicely explainjed in: GCC -fPIC option I have many source files those are managed through makefile for build. It's difficult to segregate source files that is meant ...
2 votes
2 answers
330 views
Want good understanding on shared libraries at the memory level
Please somebody help. I am creating a shared library and when run with this command this gives a error "gcc -shared libx.o -o libx.so" /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-...
0 votes
1 answer
658 views
Missing output or input when running c++ binary in docker
Building a cpp binary inside a docker builder with cmake FROM ubuntu:focal as builder WORKDIR /var/lib/project RUN cmake ... && make ... Then copying the built binary to final image which ...
0 votes
1 answer
365 views
SIGSEGV when returning pointer to malloc() in dlopen()'ed library
I'm observing some weird behaviour from a relatively simple piece of code and would like to ask if anybody has seen such before. The code below is a basic example for allocating memory inside a ...
0 votes
0 answers
336 views
-fPIC and -shared meaning?
I have a command line like this: $ gcc -shared -fPIC procmem.c -o libprocmem.so But i don't know what -shared and -fPIC mean? Can someone explain it to me. Thank you.
1 vote
1 answer
164 views
When would you not want to compile with -fPIC?
As mentioned here, compiling without -fPIC removes the ability for the code to be included in a library. Why would someone want to do this? Are there other reasons to compile without -fPIC?
0 votes
0 answers
298 views
Why my shared object does not compile without -fPIC
I wrote a simple shared lib which contains the usage of stdout in stdio.h. #include <stdio.h> ... fflush(stdout); ... There was no compilation issue before I added the fflush(stdout) with ...
2 votes
1 answer
212 views
Linux shared object compilation issue
My Makefile was like this earlier. export SOURCE1 = source1.c \ 1.c \ 2.c \ 3.c export SOURCE2 = source2.c \ 1.c all: gcc -Wall -W -g -O2 ${SOURCE1} -lm -lipc -...
-1 votes
1 answer
195 views
about the flags used in compilation
I ran into this while studying a line of code in cmake for building a library: -Wall -Wfloat-equal -o3 -fPIC What do these compiler flags mean and how do they work? Why do they need to be inserted?