How to configure NetBeans to statically link MinGW C++ libraries? - c++

I have built an executable file (.exe), but when I run it, a window pops up which says
The program can't start because libgcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem.
Can I configure Netbeans to include that file into the .exe file?

You can.
In Netbeans, right-click on the project node in the Projects window, then click Properties. Click the Build > Linker node. Under the Compilation Line category, there is a field named Additional options. Now enter the following line:
-static-libgcc -static-libstdc++
Click OK. Now it works.
Notice that your file is much larger than if it were compiled without the library. If you are not (yet) planning to distribute the executable, then maybe it's a better option to set the PATH environment variable. See The program can't start because libgcc_s_dw2-1.dll is missing for more details.

Related

Visual Studio 2019 Debugger "Unable to start program ... Access is denied" caused by build file [duplicate]

I have a solution in C:\full path here\VS2010\blender.sln
This solution contains many projects(around 100). When I compile them, they all work fine. I can run them without any problem, and (quite) everything works (there are some bugs).
One of the projects is ALL_BUILD, but it gives the same error if I try to debug INSTALL(another project). I'm compiling with RELWithDebInfo as configuration, and if I execute the program manually it works. It is outputted in C:\full path here\VS2010\bin\RelWithDebInfo
But if I try to run the compiler, it says
"Unable to start program
C:\full path here\VS2010\RelWithDebInfo\ALL_BUILD
Specified file cannot be found"
I tried to copy the compiled program into the path required by VS, but it raised the same error.
What should I do to solve this? Right now I set up cmake to generate also a mingw project and I compile it and debug it with gdb, but this is a really a slow and impractical workflow, and I would like to use the VS debugger.
I must say that if I compile with Debug as configuration, the program doesn't even start.
I'm using VS2010 Express on Win7 64bit
(This is a big open source program, so I don't know exactly whatever it does)
Guessing from the information I have, you're not actually compiling the program, but trying to run it. That is, ALL_BUILD is set as your startup project. (It should be in a bold font, unlike the other projects in your solution) If you then try to run/debug, you will get the error you describe, because there is simply nothing to run.
The project is most likely generated via CMAKE and included in your Visual Studio solution. Set any of the projects that do generate a .exe as the startup project (by right-clicking on the project and selecting "set as startup project") and you will most likely will be able to start those from within Visual Studio.
I had the same problem :)
Verify the "Source code" folder on the "Solution Explorer", if it doesn't contain any "source code" file then :
Right click on "Source code" > Add > Existing Item > Choose the file You want to build and run.
Good luck ;)
I think that what you have to check is:
if the target EXE is correctly configured in the project settings ("command", in the debugging tab). Since all individual projects run when you start debugging it's well possible that only the debugging target for the "ALL" solution is missing, check which project is currently active (you can also select the debugger target by changing the active project).
dependencies (DLLs) are also located at the target debugee directory or can be loaded (you can use the "depends.exe" tool for checking dependencies of an executable or DLL).

Visual Studio doesn't recognize opencv: unable to locate DLL [duplicate]

I am trying just a basic program with OpenCV with the following code:
#include "cv.h"
#include "highgui.h"
int main()
{
IplImage* newImg;
newImg = cvLoadImage("~/apple.bmp", 1);
cvNamedWindow("Window", 1);
cvShowImage("Window", newImg);
cvWaitKey(0);
cvDestroyWindow("Window");
cvReleaseImage(&newImg);
return 0;
}
When I run this, I get
The program can't start because
libcxcore200.dll is missing from your
computer. Try reinstalling the
program to fix this problem.
However, I can see this DLL. It exists. I have added the following to the input dependencies for my linker
C:\OpenCV2.0\lib\libcv200.dll.a
C:\OpenCV2.0\lib\libcvaux200.dll.a
C:\OpenCV2.0\lib\libcxcore200.dll.a
C:\OpenCV2.0\lib\libhighgui200.dll.a
What gives? I'm using visual studio 2008.
When I link the .dll files instead of .dll.a files, I get
fatal error LNK1107:invalid or corrupt
file: cannot read at 0x3F8
libcv200.dll
I followed instructions on http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010 but was still stuck on exactly the same problem, so here's how I resolved it.
Fetched MSVC 2010 express edition.
Fetched Win 32 OpenCV 2.2 binaries and installed in default location.
Created new project.
Project setup
Project -> OpenCV_Helloworld Properties...Configuration Properties -> VC++ Directories
Include Directories... add: C:\OpenCV2.2\include\;
Library Directories... add: C:\OpenCV2.2\lib;C:\OpenCV2.2\bin;
Source Directories... add:
C:\OpenCV2.2\modules\calib3d\src;C:\OpenCV2.2\modules\contrib\src;C:\OpenCV2.2\modules\core\src;C:\OpenCV2.2\modules\features2d\src;C:\OpenCV2.2\modules\flann\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\gpu\src;C:\OpenCV2.2\modules\highgui\src;C:\OpenCV2.2\modules\imgproc\src;C:\OpenCV2.2\modules\legacy\src;C:\OpenCV2.2\modules\ml\src;C:\OpenCV2.2\modules\objdetect\src;C:\OpenCV2.2\modules\video\src;
Linker -> Input -> Additional Dependencies...
For Debug Builds... add:
opencv_calib3d220d.lib;opencv_contrib220d.lib;opencv_core220d.lib;opencv_features2d220d.lib;opencv_ffmpeg220d.lib;opencv_flann220d.lib;opencv_gpu220d.lib;opencv_highgui220d.lib;opencv_imgproc220d.lib;opencv_legacy220d.lib;opencv_ml220d.lib;opencv_objdetect220d.lib;opencv_video220d.lib;
At this point I thought I was done, but ran into the problem you described when running the exe in debug mode. The final step is obvious once you see it, select:
Linker -> General ... Set 'Use Library Dependency Inputs' to 'Yes'
Hope this helps.
Just add C:\OpenCV2.0\bin into your PATH environment variable
or
When you install OpenCV,
Choose the option, Add OpenCV to the system PATH for current user which is not default one
Just for your information,after add the "PATH",for my win7 i need to reboot it to get it work.
In Visual Studio 2013 you need to add this to the Environment Variables and then Restart your pc. This is the path where .dll file located in.
I have had numerous problems with opencv and only succeded after a gruesome 4-6 months. This is the last problem I have had, but all of the above didn't work. What worked for me was just copying and pasting the opencv_core2*.dll (and opencv_highgui2*.dll which it will ask for since you included this as well) into the release (or debug folder - I'm assuming. Haven't tested this) folder of your project, where your application file is.
Hope this helps!
You just need to add the folder of the needed dll file (or files) to your system "Environment Variables" in "Path".
Your problem will 100% be resolved. I had this problem too.
just open the bin folder and copy and paste the .dll files to the folder you are working in..it should fix the problem
As to #Marc's answer, I don't think VC uses the path from the OS. Did you add the path to VC's library paths. I usually add the DLLs to the project and copy if newer on the build and that works very well for me.
you can find the opencv_core248 and other dlls in opencv\build\x86\vc12\bin folder. Just copy the dlls you require into system32 folder. And your app should start working in a flash ! Hope it helps.
This might be like resurrecting a dead horse. But just so it's out there, the reason why the answer to these types of questions to simply put dll's into the system32 folder is because that folder is in the os's system path.
It's actually best practice to provide the os with a path link.
With windows 10
open up file explorer
right click on "this pc" and select "properties"
Now in the "Control Panel\System and Security\System" window that comes up, click on "Advanced System Settings" from the left hand panel.
At the bottom of the next window, click on the "Environment Variables" button.
On the next window, there are two panels, the top one is for modifying variables to the current user, and the bottom panel is for modifying variables to the system. On the bottom panel, find the variable "Path" and click it to select it, then click on the "edit" button.
Here you can then create, edit, delete, or update the different paths for the system. For example, to add mingw32-make to the system so you can access that command via command prompt, click new, then paste in the path to the bin. Example path, "D:\Qt\Tools\mingw730_64\bin", no quotation marks nor additional whitespaces.
Click ok on all the windows so that the changes are saved, then reboot your computer for the changes to be loaded.
The ".a" at the end of your DLL files is a problem, and those are there because you didn't use CMAKE to build OpenCV 2.0. Additionally you do not link to the DLL files, you link to the library files, and again, the reason you do not see the correct library files is because you didn't use CMAKE to build OpenCV 2.0. If you want to use OpenCV 2.0 you must build it for it to work correctly in Visual Studio. If you do not want to build it then I would suggest downgrading to OpenCV 1.1pre, it comes pre-built and is much more forgiving in Visual Studio.
Another option (and the one I would recommend) is to abandon OpenCV and go with EmguCV. I have been playing with OpenCV for about a year and things got much easier when I switched to EmguCV because EmguCV works with .NET, so you can use a language like C# that does not come with all the C++ baggage of pointers, header files, and memory allocation problem.
And as for the question of 64bit vs. 32bit, OpenCV does not officially support 64bit. To be on the safe side open your project properties and change the "Platform Target" under the "Build" tab from "Any CPU" to "X86". This should be done any time you do anything with OpenCV, even if you are using a wrapper like EmguCV.
Copy all .dll from /bin in System32
Just copy the .dll files to C:\windows\system32\
No need to do any of that. It is a visual studio error.
just go here:
http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=31354
and download the appropriate fix for your computer's OS
close visual studio, run the fix and then restart VS
The code should run without any error.

Getting dll include to work in Visual Studio

I am new to Visual Studio, and to using .dlls, and I am trying to get portaudio running, but have not had success.
I built the .dll file, and created a console application project in VS,
I added the portaudio .lib file to "Additional Dependencies" in the solution properties -> linker -> input options.
I then added the directory for portaudio.h to VC++ Directories --> "Include Directories"
After those steps, I was able to build example code without errors, but when I run the program I would get this error:
The program can't start because portaudio_x86.dll is missing from your computer. Try reinstalling the program to fix this problem.
I tried adding the directory to where the dll and lib files are to "Executable Directories" but still I get the same error.
I don't know what else I need to do to get the dll working in VS. Any help is much appreciated.
The easiest solution is to move the created DLL to the same directory where your executable is running. There is no need to make project setting changes.
The other solution is to move the DLL to a directory specified in your PATH statement, or will be found by Windows using the Dynamic Link Library Search Order criteria.

How do I inform the debugger of the location of run-time linked DLL files?

I have a C++ program that uses the freeglut library (and hence requires the freeglut.dll at run-time. I have added the folder C:\Program Files\Common Files\freeglut\bin to my PATH environment variable.
To confirm that the location is correct, when I compile my program (debug build) and run the resulting .exe file, it works fine (the freeglut.dll file is not in the same directory as the executable).
However, when I run the program directly from the VS2012 debugger, I get this message:
The program can't start because freeglut.dll is missing from your computer. Try reinstalling the program to fix this problem.
I know that one solution is to place the freeglut.dll file in the directory of the executable. This is what I've been doing so far, but I would much rather simply inform VS2012 (or my program) of where to find the dll file. Note that this post also seems loosely related, but it doesn't seem to contain an answer relevant to what I am trying to achieve (I just want the debugger to look in the same place for DLLs as any other program!).
How do I achieve this in VS2012? Icing on the question cake would be an explanation as to why the debugger doesn't just look in the PATH variable like any other program...
You can also set project based Environment:
Open project Properties
Go to Configuration Properites -> Debugging
Enter the path in Environment, eg:
PATH=$(PATH);C:\Program Files\Common Files\freeglut\bin
Restart Visual Studio after modifying your PATH variable.
What I did actually worked. I just didn't restart VS...

Eclipse won't change output type in C++

I started an Eclipse project as an executable. It worked correctly. Then I changed it to a DLL in Project Properties -> C/C++ Build -> Settings -> Build Artifact -> Artifact Type. It still worked. (this was all with basically Hello World functionality)
So I included a bunch of stuff in my project file to actually move toward the app I want to build. I couldn't get it to quite compile, but I've included a lot of paths and libraries that I don't want to have to re-enter (or I'd just start a new project). Just to find out if I could still compile Hello World with all these includes, I changed it back to an executable in the same spot as above. It seems to work, in that it changes it on that screen; and it even changes the file extension that it feeds to the /OUT parameter of the linker. But it's still passing the /DLL parameter to the linker, as well, and I can't find the project property page where I can remove this.
Note that, when I copy-paste the command line that the Eclipse console spits out, to the command prompt and remove the /DLL parameter manually, it links properly and forms an executable that produces the correct functionality. But when I try to run the exe from the IDE, or whenever it tries to rebuild, it gives me a message box error saying my process has encountered a problem.
Error starting process.
Cannot run program "C:\Users\2659\workspace\MoreStuff\Debug\MoreStuff.exe": Launching failed
Cannot run program "C:\Users\2659\workspace\MoreStuff\Debug\MoreStuff.exe": Launching failed
Cannot run program "C:\Users\2659\workspace\MoreStuff\Debug\MoreStuff.exe": Launching failed
How can I remove this /DLL flag so that I can have actual control over what my project is outputting?
I just had a similar problem: I created a new C++ project with shared artifact nature and wanted to test it by adding a main function and a new executable build option.
In order to successfully change the nature you have also to go to Project Properties -> C/C++ Build -> Settings -> G++ Linker -> Shared Library Settings and (in the proper configuration) uncheck the Shared option.
It worked for me.