小编Har*_*ddy的帖子

如何正确使用 -fPIC 和 -fPIE GCC 选项

我有这样的目录结构

dir1
    one.c
    two.c
dir2
    three_main.c
    four.c
Run Code Online (Sandbox Code Playgroud)

我需要libdir1.so从所有c文件中创建一个共享库,并从所有c文件中dir1
创建一个可执行文件以及my_exedir2libdir1.so

我分两步创建.so可执行文件。

.so step1:    gcc -c -fPIC -g -O2 -pthread -o one.o one.c
              gcc -c -fPIC -g -O2 -pthread -o two.o two.c
.so step2:    gcc -shared -g -O2 -pthread -o libdir1.so one.o two.o


exe step1:    gcc -c -fPIE -o three_main.o three_main.c
              gcc -c -fPIE -o four.o four.c
exe step2:    gcc -Wall -g -L -ldir1 -o my_exe three_main.o four.o
Run Code Online (Sandbox Code Playgroud)

现在我的问题是...... …

c gcc compilation elf

8
推荐指数
1
解决办法
4610
查看次数

标签 统计

c ×1

compilation ×1

elf ×1

gcc ×1