简体   繁体   English

为什么我的c ++程序找不到必要的.dll文件?

[英]Why can't my c++ program find the necessary .dll file?

I am trying to use OpenCV (a computer vision library), which appearently uses a few .dll files, located in C:\\OpenCV\\bin (which has been added to the system PATH variable). 我正在尝试使用OpenCV(计算机视觉库),它显然使用了几个.dll文件,位于C:\\OpenCV\\bin (已添加到系统PATH变量中)。 However, if I try to run a simple test program, it gives a system error: 但是,如果我尝试运行一个简单的测试程序,它会给出一个系统错误:

The program can't start because highgui.dll is missing from your computer. 程序无法启动,因为您的计算机缺少highgui.dll。 Try reinstalling the program to fix this problem. 尝试重新安装该程序以解决此问题。

If I copy the highgui.dll file into the system32 folder, it works, but I don't want to have to put all the necessary .dll files in the system32 folder. 如果我将highgui.dll文件复制到system32文件夹,它可以工作,但我不想将所有必需的.dll文件放在system32文件夹中。

Does anyone know why the .dll file can't be found or what I should do to fix it? 有谁知道为什么无法找到.dll文件或我应该怎么做才能修复它?
(I already checked all paths in the PATH variable for validity.) (我已经检查了PATH变量中的所有路径的有效性。)

I tracked down the executable that was built by Netbeans before running and launched it, and it gave no errors (so Netbeans probably uses its own paths for executing), so tried to find out how I could make Netbeans search the right paths for the DLLs, and after adding an environment variable PATH=C:/OpenCV2.1/bin (Project Properties > Run > Environment), the program ran correctly! 我在运行并启动它之前跟踪了Netbeans构建的可执行文件,它没有给出任何错误(因此Netbeans可能使用自己的路径执行),因此试图找出如何使Netbeans搜索DLL的正确路径,并在添加环境变量PATH = C:/OpenCV2.1/bin (项目属性>运行>环境)后,程序正确运行!
I do hope this is not some sort of hack that 'acdidentally' solves my problem while creating worse side-effects... 我希望这不是一种“偶然”解决我的问题同时产生更糟糕的副作用的黑客行为......
Thanks for the help! 谢谢您的帮助!

Have you tried copying highgui.dll into your build folder. 您是否尝试过将highgui.dll复制到您的构建文件夹中。 As it is dynamically linked your program will look locally to find it and if it is not being copied into your build directory it won't be able to find it. 由于它是动态链接的,因此您的程序将在本地查找以找到它,如果它没有被复制到您的构建目录中,它将无法找到它。

How is the program being launched and how is the PATH variable being updated? 如何启动程序以及如何更新PATH变量?

If you update the path in a command window, but launch the app from your IDE or from the Windows desktop, the environment for the launched process will probably have a different PATH setting than the environment for your command window. 如果在命令窗口中更新路径,但从IDE或Windows桌面启动应用程序,则启动进程的环境可能具有与命令窗口环境不同的PATH设置。

Similarly if you change the PATH in the System Control Panel applet, it might not have an effect on an IDE or command window that was launched before you made the PATH edit. 同样,如果更改“系统控制面板”小程序中的PATH,它可能不会影响在进行PATH编辑之前启动的IDE或命令窗口。

I had this problem using Visual Studio 12 and after checking to make sure I had no typos in my PATH for the tenth time, I noticed there was a space after the semi-colon from the previous path. 我使用Visual Studio 12时遇到了这个问题,经过检查以确保我的PATH第十次没有拼写错误,我注意到前一个路径的分号后面有一个空格。 I removed it and Visual Studio was able to find the DLLs I needed. 我删除它,Visual Studio能够找到我需要的DLL。

If you have multiple paths stored in your PATH variable, make sure they are separated by semi-colons with no spaces . 如果PATH变量中存储了多个路径,请确保它们由没有空格的分号分隔。

I am using OpenCV 2.2 with Visual Studio 10. to create a new project i do the following steps... 1.VC++ Directories -> Include Directories -> C:\\OpenCV2.2\\include Library Directories -> C:\\OpenCV2.2\\lib 2.C/C++ -> General -> Additional Include Directories ->C:\\OpenCV2.2\\bin 3.Linker -> Input -> opencv_core220.lib;opencv_highgui220.lib;opencv_calib3d220.lib;opencv_contrib220.lib;opencv_features2d220.lib;opencv_ffmpeg220.lib;opencv_flann220.lib;opencv_gpu220.lib;opencv_imgproc220.lib;opencv_legacy220.lib;opencv_ml220.lib;opencv_objdetect220.lib;opencv_ts220.lib;opencv_video220.lib; 我正在使用OpenCV 2.2与Visual Studio 10.创建一个新项目我执行以下步骤... 1.VC ++目录 - >包含目录 - > C:\\ OpenCV2.2 \\ include库目录 - > C:\\ OpenCV2。 2 \\ lib 2.C / C ++ - > General - > Additional Include Directories - > C:\\ OpenCV2.2 \\ bin 3.Linker - > Input - > opencv_core220.lib; opencv_highgui220.lib; opencv_calib3d220.lib; opencv_contrib220.lib; opencv_features2d220.lib; opencv_ffmpeg220.lib; opencv_flann220.lib; opencv_gpu220.lib; opencv_imgproc220.lib; opencv_legacy220.lib; opencv_ml220.lib; opencv_objdetect220.lib; opencv_ts220.lib; opencv_video220.lib;

  1. i copy all the dll files to the project debug folder. 我将所有dll文件复制到项目调试文件夹。 it gives me no hitch and everything is fine.. 它没有给我带来任何障碍,一切都很好..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM