天嵌 ARM开发社区

 找回密码
 注册
查看: 2004|回复: 4

事例程序hello_cn 运行出现Segmentation fault

[复制链接]
linwb 发表于 2013-12-17 20:35:40 | 显示全部楼层 |阅读模式
我用安装文件时提供的hello_cn生成的arm可执行文件,用发图片传到板子上却总是出现Segmentation fault,是我哪里做错了吗
下面是我在终端运行的程序
[root@Lin hello_cn]# make clean
rm -f moc_hello_cn.cpp
rm -f hello_cn.o main.o moc_hello_cn.o
rm -f *~ core *.core
[root@Lin hello_cn]# ls
arm_project  hello_cn.cpp  hello_cn.pro.user  Makefile     说明
hello_cn     hello_cn.h    main.cpp           x86_project
[root@Lin hello_cn]# cd ..
[root@Lin pro]# cd ..
[root@Lin qt-4.5]# source setARM_env
[root@Lin qt-4.5]# cd pro/hello_cn/
[root@Lin hello_cn]# ./arm_project
[root@Lin hello_cn]# make
arm-linux-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../__install/arm/mkspecs/default -I. -I../../__install/arm/include/QtCore -I../../__install/arm/include/QtNetwork -I../../__install/arm/include/QtGui -I../../__install/arm/include -I. -I. -I. -o hello_cn.o hello_cn.cpp
arm-linux-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../__install/arm/mkspecs/default -I. -I../../__install/arm/include/QtCore -I../../__install/arm/include/QtNetwork -I../../__install/arm/include/QtGui -I../../__install/arm/include -I. -I. -I. -o main.o main.cpp
/opt/EmbedSky/qt-4.5/__install/arm//bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../__install/arm/mkspecs/default -I. -I../../__install/arm/include/QtCore -I../../__install/arm/include/QtNetwork -I../../__install/arm/include/QtGui -I../../__install/arm/include -I. -I. -I. hello_cn.h -o moc_hello_cn.cpp
arm-linux-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../__install/arm/mkspecs/default -I. -I../../__install/arm/include/QtCore -I../../__install/arm/include/QtNetwork -I../../__install/arm/include/QtGui -I../../__install/arm/include -I. -I. -I. -o moc_hello_cn.o moc_hello_cn.cpp
arm-linux-g++ -Wl,-O1 -Wl,-rpath,/opt/EmbedSky/qt-4.5/__install/arm/lib -o hello_cn hello_cn.o main.o moc_hello_cn.o    -L/opt/EmbedSky/qt-4.5/__install/arm//lib -lQtGui -L/tslib-1.4/lib -L/opt/EmbedSky/qt-4.5/__install/arm//lib -lts -lQtNetwork -lQtCore -lm -lrt -ldl -lpthread
[root@Lin hello_cn]# file hello_cn
hello_cn: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
[root@Lin hello_cn]# cd /mnt/hgfs/temp/
[root@Lin temp]# ls
first  first.desktop  first.png  first.rar  hello_cn  Lin  Linux  mainwindow
[root@Lin temp]# file hello_cn
hello_cn: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped

wbz073 发表于 2013-12-18 11:11:28 | 显示全部楼层
把Makefile里面的-O2给去掉 看看
 楼主| linwb 发表于 2013-12-18 20:08:15 | 显示全部楼层
wbz073 发表于 2013-12-18 11:11
把Makefile里面的-O2给去掉 看看

还是不可以啊 是不是因为我直接用ftp传到板子里的关系啊 必须要用工具生成文件系统加进去 不能直接穿到含有qt4.5的系统中啊
wbz073 发表于 2013-12-19 08:40:21 | 显示全部楼层
linwb 发表于 2013-12-18 20:08
还是不可以啊 是不是因为我直接用ftp传到板子里的关系啊 必须要用工具生成文件系统加进去 不能直接穿到含 ...

段错误常见错误原因:
1,数组越界.
2,访问空,野指针或未被初始化的指针.
你检查下你的源码。
 楼主| linwb 发表于 2013-12-19 11:42:25 | 显示全部楼层
wbz073 发表于 2013-12-19 08:40
段错误常见错误原因:
1,数组越界.
2,访问空,野指针或未被初始化的指针.

应该不会错啊 我用的是光盘里安装qt4.5生成的hello_cn程序啊 应该不会有错才对的啊
main.c
#include <QtGui>

#include "hello_cn.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

    Hello *w = new Hello;
    w->show();
//    w->showFullScreen();        //全屏显示
    return app.exec();
}
hello_cn.cpp
/********************************************************************************
** 文件名称:hello_cn.cpp
**
** 版权所有:广州天嵌计算机科技有限公司
**
** 开发者:Arthur
**
********************************************************************************/

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "pthread.h"

#include "hello_cn.h"

Hello::Hello(QWidget *parent)
        : QWidget(parent)
{

    setWindowTitle(tr("Hello测试程序"));
    setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
    this->setEnabled(true);
    this->resize(315, 202);
   
    ID_info_massage = new QLabel(this);
    ID_info_massage->setObjectName(QString::fromUtf8("ID_info_massage"));
    QFont font;
    font.setStyleStrategy(QFont::PreferDefault);
    ID_info_massage->setFont(font);
    ID_info_massage->setText(tr("hello lin"));
};

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-28 09:25 , Processed in 1.040079 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表