OpenCV c++使用外部库部署应用程序

发布于 2024-09-27 03:42:01 字数 628 浏览 2 评论 0原文

我尝试对此进行了很多搜索,但没有成功(可能是因为我没有使用正确的技术术语)。我的问题主要与链接静态库、编译和部署有关。在详细介绍之前,我的可执行文件在我的系统上编译得很好;主要问题是如何将这些作为可行的解决方案部署给其他人。

我编写了一个使用 OpenCV 静态库的基本 c++ 图像处理 exe(我使用 Project>Properties>Linker> 添加附加依赖项作为标准在 VC++ 中链接这些库)。我通过设置 VC++ 选项来指向正确的包含文件进行编译...基本上,一切都编译得很好。我现在希望能够将其部署到另一台电脑上。我知道我需要 exe + 静态库的发行版本...还有其他吗?

一些库依赖于使用 libjpeg 和 libpng;我不认为这些是标准的。另外,我已将静态库的链接器路径设置为相对路径(例如资源/库),因此它不依赖于系统,因此它知道在哪里可以找到库。基本的 OpenCV 数据结构工作正常(例如 CvPoint),但是当我尝试使用 CvLoadImage 加载图像时,应用程序崩溃了。如果我使用标准 ifstream fopen,我可以毫无问题地打开文件(但似乎无法将其放入 IplImage OpenCV 图像支柱中 - 有谁知道如何执行这些操作吗?可能与 IplImage->imageData 有关。 )。

非常感谢任何帮助。谢谢!

I've tried searching A LOT for this with no luck (possibly because I'm not using the right technical terms). My issue is mainly to do with linking static libs, compiling and deploying. Before I get into details, my executables compile fine on my system; the main issue is how to deploy these as a working solution to others.

I've written a basic c++ image processing exe that uses OpenCV static libraries (I link these in VC++ using the Project>Properties>Linker> add additional dependencies, as standard). I compile by pointing to the right include files by setting the VC++ Options... basically, it all compiles fine. I now want to be able to deploy this on another PC. I understand I'll need the release version of the exe + static libs... is there anything else?

Some of the libs rely on using libjpeg and libpng; I don't think these are included as standard. Also, I've set the linker path to the static libs to be relative (e.g. resources/libs) so it's not system dependent so it knows where to find the libs. The basic OpenCV data strucs are working fine (e.g. CvPoint), but when I try to load an image using CvLoadImage, the application crashes. If I use standard ifstream fopen instead, I can open the file with no problems (but can't seem to get it into the IplImage OpenCV image strut - does anyone know how to do these? Probably to do with IplImage->imageData.).

Any help very much appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酉 2024-10-04 03:42:01

静态库不必(也不应该)与应用程序一起分发。静态库由链接器内置到 exe 文件中。

OpenCV 崩溃的原因是找不到 libpng/libjpeg dll。 OpenCV 不会将它们链接为静态依赖项,而是在运行时使用 LoadLibrary/dlopen API。如果这些调用失败,则可能无法很好地恢复并且应用程序崩溃。如果包含 libpng/libjpeg 库,您的问题应该得到解决。

另请注意 - 某些 .lib 文件并不是真正的静态库,而只是一个薄层,它允许链接器在 DLL 中找到适当的函数并生成动态链接代码,以便程序员不必手动执行此操作。您通常会发现 .lib 文件非常小,并且您的应用程序会在 exe 启动时报告找不到 DLL 入口点。

Static libraries do not have to (and should not) be distributed with the application. Static libraries are built into the exe file by the linker.

The reason why OpenCV crashes is that it cannot find libpng/libjpeg dlls. OpenCV doesn't link them as static dependencies but uses LoadLibrary/dlopen APIs at runtime instead. If these calls fail, there's probably no nice recovery and the application crashes. Your problems should be fixed if you include the libpng/libjpeg libraries.

Also beware - some .lib files aren't truly static libraries but are just a thin layer that allows the linker to find the appropriate functions in a DLL and generate the dynamic linking code so that the programmer doesn't have to do that by hand. You will usually see that from the .lib file size that is pretty small and that your application cries that it cannot find a DLL entry point at the startup of the exe..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文