【发布时间】:2015-08-11 22:41:46
【问题描述】:
我有以下代码。
猫样本.c
#include<stdio.h>
#include "hello.c"
int main()
{
hello_world();
return 0;
}
cat hello.c
#include<stdio.h>
void hello_world()
{
printf("Hello World");
}
-
使用的编译命令:
g++ -gxcoff -maix64 -shared -fpic -fpermissive -w -Ihello.c -o sample sample.c -Xlinker -e.main
执行
$ ./sample
分段错误(coredump)
-
我尝试调试内核。但是找不到太多
$ dbx 样本核心
Type 'help' for help. [using memory image in core] reading symbolic information ...internal error: 1283-232 index("16;0;", ':') failed internal error: 1283-232 index("16;0;", ':') failed internal error: 1283-232 index("8;0;", ':') failed internal error: 1283-228 expected char ',', found ';-31,448,256;;' internal error: 1283-228 expected char ';', found ',256;;' internal error: 1283-232 index("256;;", ':') failed Segmentation fault in . at 0x7c0802a6f8010010 0x7c0802a6f8010010 (???) warning: Unable to access address 0x7c0802a6f8010010 from core请帮我解决这个核心转储问题
【问题讨论】:
-
与您的问题无关,但不要
#include源文件!而是将它们分别编译为目标文件,然后将它们链接在一起以形成最终的可执行文件。你应该#include是一个header 文件,它只包含declarations。 -
“gcc -o sample sample.c”有效吗?
-
是的,这行得通。但我想知道问题背后的原因。