码迷,mamicode.com
首页 > 系统相关 > 详细

[linux]segvcatch简单使用

时间:2015-07-14 20:19:48      阅读:892      评论:0      收藏:0      [点我收藏+]

标签:

https://code.google.com/p/segvcatch/

This is a crossplatform C++ library designed to convert a hardware exceptions, such as segmentation fault, or floating point errors, into a software language exceptions, which can be handled later with a try/catch construction.

Other words, it‘s a crossplatform structured exception handling (SEH).

有时候遇到段错误,我们想把这个异常抓住,segvcatch就可以帮助我们做这个事。

 

下载好segvcatch-0.9.1.zip后解压看里面的doc.h步骤即可,这里我们提取文件单独测试下

下载地址:http://pan.baidu.com/s/16ViuM

1.提取相关文件

技术分享

提取的文件如上面的全部.cpp和.h文件,Makefile后面一步再写,.so是后面生成的,.sh一个运行脚本

2.编辑Makefile

CXX        =    g++
TARGET    =    main
SOURCES    =    main.cpp
LIBS    =    -L./ -lsegvcatch
CXXFLAGS=    -Wall -fexceptions -fnon-call-exceptions
RM        =    rm -rf

$(TARGET):$(SOURCES)
    $(CXX) $^ $(LIBS) -o $@ $(CXXFLAGS)

.PHONY:clean
clean:
    $(RM) main *.so
.PHONY:lib
lib:segvcatch.cpp
    $(CXX) $^ -fPIC -shared -o libsegvcatch.so

3.编译测试(OK!)

#make lib

#make

#./main

Exception catched : My SEGV

Exception catched : My FPE

We are living yet!

 

[linux]segvcatch简单使用

标签:

原文地址:http://www.cnblogs.com/luoxiang/p/4646170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!