【问题标题】:g++ Compilation in AIX server - Throwing core dumpAIX 服务器中的 g++ 编译 - 抛出核心转储
【发布时间】: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”有效吗?
  • 是的,这行得通。但我想知道问题背后的原因。

标签: c++ c g++ aix


【解决方案1】:

g++ -gxcoff -maix64 -shared -fpic ...

上面的命令构建一个共享库,而不是你可以运行的可执行文件。从中删除 -shared 以及 -Xlinker -e.main,它应该可以正常工作。

【讨论】:

    猜你喜欢
    • 2015-07-27
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    相关资源
    最近更新 更多