小编nut*_*man的帖子

Why I cannot compile with -fPIE but can with -fPIC?

I have one interesting compilation problem. At first, please see code to be compiled.

$ ls
Makefile main.c sub.c sub.h
$ gcc -v
...
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
Run Code Online (Sandbox Code Playgroud)
## Makefile
%.o: CFLAGS+=-fPIE #[2]

main.so: main.o sub.o
    $(CC) -shared -fPIC -o $@ $^
Run Code Online (Sandbox Code Playgroud)
$ ls
Makefile main.c sub.c sub.h
$ gcc -v
...
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
Run Code Online (Sandbox Code Playgroud)
## Makefile
%.o: CFLAGS+=-fPIE #[2]

main.so: main.o sub.o
    $(CC) -shared -fPIC -o $@ $^
Run Code Online (Sandbox Code Playgroud)
//main.c
#include …
Run Code Online (Sandbox Code Playgroud)

c linux gcc fpic position-independent-code

4
推荐指数
1
解决办法
1190
查看次数

标签 统计

c ×1

fpic ×1

gcc ×1

linux ×1

position-independent-code ×1