Eclipse SIGSEV中编译的C二进制文件

时间:2014-07-22 17:12:36

标签: c eclipse gcc

我一直试图通过Eclipse运行一个正在运行的程序(为了便于调试),但我似乎无法完成它。

我有一个简单的命令,通过终端编译程序:

gcc -m32 *.c -lm

然后我可以正确执行./a.out

要在Eclipse中使用用户友好的gdb插件,我也想在Eclipse中编译和运行它。

到目前为止,我已将-lm -m32 -w添加到"杂项"项目设置中的字段" Cross GCC Compiler"以及"杂项" " Cross GCC Linker"。

下的字段

该程序似乎编译正常(见下文)。但是,当我选择libslip二进制文件并尝试执行它时,它会立即崩溃。

当我通过终端运行libslip可执行文件时,我得到以下输出:

Debug$ ./libslip 
Killed

当我通过Eclipse运行时,我得到了这个:

<terminated> libslip [C/C++ Application] <path>

gdb libslip输出如下:

Reading symbols from libslip...done.
(gdb) b 1
Breakpoint 1 at 0xb4d3: file ../SlipTest.c, line 1.
(gdb) run
Starting program: /home/christophe/School/Semester 2/Programming Language Engineering/Section 5/eclipse-workspace/slip/Debug/libslip 

Program received signal SIGSEGV, Segmentation fault.
0x00000001 in ?? ()
(gdb) 

Eclipse中编译过程的控制台输出:

19:10:24 **** Build of configuration Debug for project slip ****
make all 
Building file: ../SlipDictionary.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipDictionary.d" -MT"SlipDictionary.d" -o "SlipDictionary.o" "../SlipDictionary.c"
Finished building: ../SlipDictionary.c

Building file: ../SlipEvaluate.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipEvaluate.d" -MT"SlipEvaluate.d" -o "SlipEvaluate.o" "../SlipEvaluate.c"
Finished building: ../SlipEvaluate.c

Building file: ../SlipGrammar.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipGrammar.d" -MT"SlipGrammar.d" -o "SlipGrammar.o" "../SlipGrammar.c"
Finished building: ../SlipGrammar.c

Building file: ../SlipMain.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipMain.d" -MT"SlipMain.d" -o "SlipMain.o" "../SlipMain.c"
Finished building: ../SlipMain.c

Building file: ../SlipMemory.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipMemory.d" -MT"SlipMemory.d" -o "SlipMemory.o" "../SlipMemory.c"
Finished building: ../SlipMemory.c

Building file: ../SlipNative.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipNative.d" -MT"SlipNative.d" -o "SlipNative.o" "../SlipNative.c"
Finished building: ../SlipNative.c

Building file: ../SlipPool.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipPool.d" -MT"SlipPool.d" -o "SlipPool.o" "../SlipPool.c"
Finished building: ../SlipPool.c

Building file: ../SlipPrint.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipPrint.d" -MT"SlipPrint.d" -o "SlipPrint.o" "../SlipPrint.c"
Finished building: ../SlipPrint.c

Building file: ../SlipRead.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipRead.d" -MT"SlipRead.d" -o "SlipRead.o" "../SlipRead.c"
Finished building: ../SlipRead.c

Building file: ../SlipScan.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipScan.d" -MT"SlipScan.d" -o "SlipScan.o" "../SlipScan.c"
Finished building: ../SlipScan.c

Building file: ../SlipTest.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lm -m32 -w -MMD -MP -MF"SlipTest.d" -MT"SlipTest.d" -o "SlipTest.o" "../SlipTest.c"
Finished building: ../SlipTest.c

Building target: libslip
Invoking: Cross GCC Linker
gcc -m32 -lm -w -shared -o "libslip"  ./SlipDictionary.o ./SlipEvaluate.o ./SlipGrammar.o ./SlipMain.o ./SlipMemory.o ./SlipNative.o ./SlipPool.o ./SlipPrint.o ./SlipRead.o ./SlipScan.o ./SlipTest.o   
Finished building target: libslip


19:10:24 Build Finished (took 560ms)

CodeBlocks构建日志

-------------- Clean: Debug in Slip1 (compiler: GNU GCC Compiler)---------------

Cleaned "Slip1 - Debug"

-------------- Build: Debug in Slip1 (compiler: GNU GCC Compiler)---------------

gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipDictionary.c -o obj/Debug/SlipDictionary.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipEvaluate.c -o obj/Debug/SlipEvaluate.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipGrammar.c -o obj/Debug/SlipGrammar.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipMain.c -o obj/Debug/SlipMain.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipMemory.c -o obj/Debug/SlipMemory.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipNative.c -o obj/Debug/SlipNative.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipPool.c -o obj/Debug/SlipPool.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipPrint.c -o obj/Debug/SlipPrint.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipRead.c -o obj/Debug/SlipRead.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipScan.c -o obj/Debug/SlipScan.o
gcc -Wall -g -w  -c /home/christophe/Desktop/CodeBlocks/Slip1/Slip1/SlipTest.c -o obj/Debug/SlipTest.o
g++  -o bin/Debug/Slip1 obj/Debug/SlipDictionary.o obj/Debug/SlipEvaluate.o obj/Debug/SlipGrammar.o obj/Debug/SlipMain.o obj/Debug/SlipMemory.o obj/Debug/SlipNative.o obj/Debug/SlipPool.o obj/Debug/SlipPrint.o obj/Debug/SlipRead.o obj/Debug/SlipScan.o obj/Debug/SlipTest.o   
Output file is bin/Debug/Slip1 with size 136,52 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

1 个答案:

答案 0 :(得分:3)

终于找到了它!答案是不要手动添加-lm,而是将其添加到库中。

让它发挥作用的方法是:

右键单击项目&gt;属性&gt; C / C ++ Build&gt;设置&gt; GCC C链接器&gt;图书馆&gt;添加&#34; m&#34;。

这使它编译并运行完美! :)

我发现它归功于这个解决方案:https://stackoverflow.com/a/7860702/1225786