c ++代码无法在FreeBSD上捕获异常 [英] c++ code doesn't catch exception on FreeBSD

查看:69
本文介绍了c ++代码无法在FreeBSD上捕获异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以在许多不同的Linux发行版上运行.当我出于某种原因在FreeBSD 10.1上编译它时,catch子句停止工作,应捕获的异常使我的程序崩溃.调试时,我将catch子句之一修改为"catch(...)",但仍未捕获到异常.我想这个问题与链接程序有关,但是我不知道如何进一步调试它.当我尝试编译一个简单的引发,捕获和异常的测试程序时,它起作用了-因此,我猜链接器无法正确链接不同的对象.

I have a program running on many different linux distros. When I compile it on FreeBSD 10.1 for some reason the catch clauses stop working and exceptions that should get caught crash my program. When debugging I modified one of the catch clauses to "catch (...)" and still the exception wasn't caught. I guess the issue is related to the linker, but I don't know how to debug it futher. When I tried compiling a test program that simply throws and catches and exception it worked - so I guess the linker fails to link the different objects properly.

谁知道我该怎么解决?谢谢

Anyone know how can I solve it? Thanks

编译示例(命令中的原始路径较长,为清楚起见将其删除):

compilation examples (original paths in the commands are longer, deleted them for clarity):

我编译了许多这样的类:

I compiled many classes like this:

/usr/local/bin/g++ -O3 -c   -DFreeBSD  -D_FreeBSD  -I. -I/usr/local/openjdk8/include -I/usr/local/openjdk8/include/freebsd -DBOOL_DEFINED -D_BOOL -DFreeBSD -fPIC -I../../../../common/cpp -DVERSION_MAJOR=8 -DVERSION_MIDDLE=2 -DVERSION_MINOR=8 -DNSC_DEBUG -DUSE_HINT_FILES -o CNBCommand.o CNBCommand.cpp

然后使用创建一个存档

ar srv "bin/FreeBSD_10.1-RELEASE/mechanism.a" <many .o files compiled like above>

最后的可执行文件链接到:

And the final executable is linked with:

/usr/local/bin/g++ -O3  -B/usr/local/bin -rpath=/usr/local/lib -lstdc++ -lpthread  -o "../bin/FreeBSD_10.1-RELEASE/nbstatus" <many *.o files compiled like above> bin/FreeBSD_10.1-RELEASE/mechanism.a

这是我使用的g ++:

This is the g++ I use:

/usr/local/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc49/gcc/x86_64-portbld-freebsd10.1/4.9.3/lto-wrapper
Target: x86_64-portbld-freebsd10.1
Configured with: ./../gcc-4.9-20141126/configure --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc49 --libexecdir=/usr/local/libexec/gcc49 --program-suffix=49 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc49/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --with-ecj-jar=/usr/local/share/java/ecj-4.5.jar --enable-languages=c,c++,objc,fortran,java --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc49 --build=x86_64-portbld-freebsd10.1
Thread model: posix
gcc version 4.9.3 20141126 (prerelease) (FreeBSD Ports Collection)

推荐答案

您必须与 -Wl,-rpath =/usr/local/lib/gcc< VERSION> 链接,否则链接到 libc ++ ,它与gcc使用的标头不匹配.

You have to link with -Wl,-rpath=/usr/local/lib/gcc<VERSION> or you'll link against libc++, which doesn't match the headers gcc uses.

检查 pkg info -Dx gcc 的正确路径.

这篇关于c ++代码无法在FreeBSD上捕获异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆