MinGW:与 LAPACK 和 BLAS 链接会导致 C++未处理的异常
情况很简单,但是很奇怪。当我在没有 LinearAlgebra.o 源代码(需要链接到 LAPACK)的情况下编译程序时,会捕获并处理 C++ 异常。当我不包含该编译单元但仍链接到库 (-llapack -lblas
) 时,会捕获并处理异常。但是一旦我把它放在那里(其中的代码运行得很好),C++异常就不再被正确处理,并且我得到Windows崩溃处理程序“程序已停止响应返回总部的报告”废话。
在这里我阐明了这个源文件中发生的情况。我确实把它做得很简单,但我不确定它是否真的是犹太洁食。
我怀疑是调用 FORTRAN 例程导致 C++ 异常停止工作的原因。但我不知道如何解决这个问题。
更新:
我很高兴找到了解决此问题的临时解决方法:我正在使用 MinGW 的 gfortran 编译器直接编译我当前正在使用的 LAPACK 和 BLAS 例程。
使用 -lgfortran
和 g++
将这些目标文件链接到我的 C++ 项目中可以完美地工作,并且我的异常仍然得到正确处理!作为奖励,这允许我只包含我打算使用的 LAPACK 例程,所以现在我不再需要链接 ~4MB 的库。
编辑:我认为如果我静态链接一个库,它只会“获取它需要的内容”,因此在这种情况下,4MB 并不重要。
The situation is simple, but strange. When i compile my program without the LinearAlgebra.o source (which requires linking to LAPACK), C++ exceptions are caught and handled. When I do not include that compilation unit but still link to the libraries (-llapack -lblas
), exceptions are caught and handled. But once I get it in there (the code from it runs just fine), C++ exceptions are no longer handled correctly, and I get Windows crash handler "Program has stopped responding report back to HQ" nonsense.
Here I shed light on what is going on inside this source file. I did keep it pretty simple, but I'm not sure if it's really Kosher.
I suspect it is something about invoking FORTRAN routines which causes C++ exceptions to stop working. But I have no idea how to go about fixing this.
UPDATE:
I am very glad to have found a temporary workaround for this issue: I am using MinGW's gfortran
compiler to directly compile the LAPACK and BLAS routines I am currently using.
Linking those object files into my C++ project using -lgfortran
with g++
works flawlessly, and my exceptions are still being correctly handled! As a bonus this allows me to only include what LAPACK routines I intend to use, so now I no longer have to link a ~4MB library.
Edit: I think if I statically link a library it only "grabs what it needs" so it being 4MB wouldn't matter in that case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 GotoBLAS2 取得了很好的成果。运行包含的脚本会生成一个针对我的机器优化的巨大的 19MB 静态库。只需将其连接即可完美运行。我所有的 Fortran 风格调用都可以正常工作。
I have had great results with GotoBLAS2. Running the script included produces a massive 19MB static library optimized for my machine. It works flawlessly by simply linking it. All of my fortran style calls just work.