I am successfully compiling (with MinGW) and running my C++ program (which calls Java classes through JNI) consisting of multiple files on my Win7-64bit system. Compiling and running is done by 2 batch files. I installed Visual Studio C++ 2010 some time ago but haven't used it since.
I am now trying to deploy this program to another computer running WinXP-32bit and I am facing a "missing msvcr100.dll" error. I installed the latest MinGW and JDK, I compiled my program using the same batch file, but when I'm running it, I get the error. Visual Studio is not used in any part of the building (and I don't want it to), so I find it strange that I get this message about an MSVC++ dll.
compile.bat
rem Set the include paths for the JNI header files("include" and "include\win32" inside the jdk (32-bit) directory).
set JDK_INCLUDE="C:\Program Files\Java\jdk1.7.0\include"
set JDK_INCLUDE_WIN32="C:\Program Files\Java\jdk1.7.0\include\win32"
set PATH=%PATH%;C:\MinGW\bin
rem Build an import library for the jvm.dll from the .\lib\jvm.def file (see http://www.inonit.com/cygwin/jni/invocationApi/archive.html)
dlltool --input-def .\lib\jvm.def --kill-at --dllname jvm.dll --output-lib .\lib\libjvm.dll.a
rem Set the import library directory.
set JVM_IMPORT_DLL=".\lib"
rem Compile all files (including the IngToolTest.cpp) and create an executable file .\bin\COFORM_JNI.exe
g++ -I%JDK_INCLUDE% -I%JDK_INCLUDE_WIN32% .\src\DataTypes\file1.cpp .\src\IngestionTool\file2.cpp ... .\src\file25.cpp Test.cpp -L%JVM_IMPORT_DLL% -ljvm -o .\bin\executable.exe
pause
run.bat
Rem Set the environment parameter to the path where the properties file resides.
set CONFIG_DIR=..
Rem Set the environment parameter to the actual IP of your VM machine.
set VM_URL=139.191.173.43
Rem Set the location of the jvm.dll (32-bit)
set PATH=%PATH%;C:\Program Files\Java\jdk1.7.0\jre\bin\client
move *.rdf RDFS
.\bin\executable.exe
pause
Is it possible that one of my external includes is causing this? Here they are:
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <jni.h>
#include <vector>
#include <string.h>
#include <fstream>
using namespace std;
I would appreciate any help to overcome this error.
K
While MinGW is a distribution of GCC, to allow it to run natively on Windows without having a Linux emulation layer like Cygwin it does not use the GNU C library. Instead it uses Microsoft's C Runtime. I have not used MinGW for a while, when it used MSVCRT.DLL from VC++ 6.0, which was more or less ubiquitous in Windows installations at the time as it shipped with installations since late Win95 editions.
It is quite possible that your installation of Windows does not have the later runtime if it was not distributed with it and you have not installed any application with which it was distributed. It may be that you have only the 64 bit DLL and need to install the 32 bit DLL.
The simple solution is to install Microsoft's VC++ re-distributable package(s).
Microsoft Visual C++ 2010 Redistributable Package (x64)
Microsoft Visual C++ 2010 Redistributable Package (x86)
Added Note: According to both http://mingw-w64.sourceforge.net/ and http://www.mingw.org, MinGW still depends on MSVCRT.DLL, so I wonder what you have done or where you obtained your distribution that makes it depend on MSVCRT100.DLL? Some experimental build perhaps?
The DLL contains the runtime for compiled programs. It must be installed on the other machine to be able to run the program.
Standard program distributions have an install package that does this for you, or you can install it manually.
See here for download instructions
http://www.microsoft.com/download/en/details.aspx?id=5555
MinGW merely emulates Linux OS calls. Let me explain..
When you ceate a binary that runs on a certain OS, that binary needs to know how to interact with the underlying OS. This is important for things like memory allocation. The binary doesn't natively "know" how to allocate RAM, instead, it asks the host OS to give it some RAM. It does this, by calling an allocation function that resides at a predetermined "address" inside the OS.
How does the application know what "address" the allocation method exists at?
When you compile the binary, you bind to it a "C runtime library (CRT)". This library contains all the mappings for OS interactions that the binary will need. So for example, when you link the CRT, the binary now knows where it can find the memory allocation function that is exposed by the OS.
MinGW, inserts an emulation layer such that an application thinks its linking to a Linux CRT, but really, the emulation layer just redirects calls to the Microsoft CRT.
Windows, has a number of different CRTs available. On all distributions, you can find somewhere in %PATH%, the file msvcrt.dll. This file, provides all support that a binary would need to run in the OS.
When you install Visual Studio, you get updated versions of the CRT:
In VS 2005: msvcrt80.dll
In VS 2008: msvcrt90.dll
In VC 2010: msvcrt100.dll
Apparently, by installing Visual Studio, you've caused MinGW's emulation layer to link against msvcrt100.dll, rather than the msvcrt.dll, that comes distributed on all windows machines. I don't know why this is happening, but this IS what is happening.
EDIT
The command:
dlltool --input-def .\lib\jvm.def --kill-at --dllname jvm.dll --output-lib .\lib\libjvm.dll.a
Which is producing a file that links in jvm.dll might creating the msvcrt100.dll dependency. That is, jvm.dll might be dynamically linked against the newest CRT, and because you require jvm.dll you indirectly need msvcrt100.dll.
Are there any dll's found in ""C:\Program Files\Java\jdk1.7.0\bin"?
Related
I have created a C++ standalone exe with VS2019.
This exe uses 1 external ressource file.
This exe creates WAV files.
It does not use any special libraries.
I have been asked if this application runs under Linux, too.
What would I have to do / check to see if / how I can compile my application for Linux, and would that be possible using VS2019?
Thank you very much for the help.
ps: Here is a screenshot of the properties of my project:
Usually to build C++ applications for Linux, you must first use a compiler that will build for the target OS. In this case VS2019 (and it's associated compiler) builds executables for Windows only.
If you're trying to target Linux, you have two options:
You can move over to a Linux system and build your project with the GNU c++ compiler (I recommend using CMAKE to build your project since it's not tied to any particular IDE and can generate makefiles for gcc). https://cmake.org/cmake-tutorial/
You can install the Windows Subsystem for Linux (WSL) and do a remote build with VS2019. You'll see more and more of this these days in production environments. https://devblogs.microsoft.com/cppblog/linux-development-with-c-in-visual-studio-2019-wsl-asan-for-linux-separation-of-build-and-debug/
Hope this helps!
When I compile C++ code that uses openmp libs with visual studio, the program is very portable - because it runs in other machines with Windows without problems.
When I compile the C++ code with Eclipse CDT (oxygen and g++ cygwin) for Windows, in general, I need to install the correct runtime libs in the other machines to be able to run the program. I don't find it practical.
Based on this:
1) What is the right way to compile the code including all libs (g++ and openmp) to run in another Windows system?
2) How can do this in Eclipse CDT for Windows?
The problem is not in compiling, but in distributing. Windows and windows toolchains intend to use dynamic linking. Now, if created software are dependent on particular version of runtime, which includes side-by-side build, they can be run only if exactly that build is installed. Several builds of same library version may exist, they are fetched using side-by-side (SxS) mechanics.
On Linux platform this problem is solved through package manager and dependencies. On Windows you have to create an installer, which would contain or have ability to download proper version of libraries. Also installer may do proper changes to OS settings, and register them , for future rollback.
Note, that runtime libraries have debug variants which cannot be distributed and debug build of software must be run on developer system only.
"Portable" apps that appear here and there and can be run without installation, have special status not to be dependant on SxS run-time library. To my knowledge cygwin and mingw32 allowed to create such, the 64bit project of mingw had problems with that. But they are still dependant on particular versions of system .dll and may break or malfunction in case of mismatch.
Even in that case you still need some .dll, from mingw, cygwin, Qt, whatever you use and what is not a part of OS, to place them where program can reach them. Which can be folder comtaining the executable. Static linking became a gimmick of past for desktops, because of code bloat - dynamic library size easily can be dozens of megabytes.
And last: you don't compile anything with Visual Studio or with Eclipse CDT. Both designed to use various compilers, it's juse environments. You have to specify normal;y, what compiler your IDE uses, not what IDE you use to run ot.
So I have been programming in console C++ for a while, but I finally decided to try graphical applications using OpenGL. It took me a while to learn that GLUT and other libraries are obsolete, so I began installing and preparing GLEW and FreeGLUT. I managed to get to the point were my includes are working; however, now I'm running into this problem:
Visual Studio is telling me that I don't have glew32.dll when it is clearly sitting in the system32 folder. Is this not the default folder for these libraries?
In addition, every time I run my program (and hence get this error) the visual studio process continues running in the background, even after the program is closed. It refuses to be ended and it causes another problem: whenever I reenter Visual Studio I get a message saying that the default storage location is currently in use by another instance of visual studio (the one running in the background.) As a result, to continue working I have to restart my computer every time.
Does anyone have any clue what could be wrong with this and how I could get things up and running? This is my first time installing libraries, but I haven't touched random things in the system folder (at least not intentionally) and I've been careful to clean up behind myself when I've done something I shouldn't have.
Other info:
Visual Studio 2012
Latest stable releases of freeGLUT and GLEW
Windows 8.1 64bit
There are a few things worth mentioning here:
You really should not even bother with using the dynamic linking version of glew (glew32.lib). Just link against the static linking library (glew32s.lib) and forget that the DLL version ever existed.
The DLL version is more trouble than it is worth, especially since it will not work with other compilers (e.g. g++) on Microsoft Windows.
For goodness' sake, do not install glew32.dll to System32!
Never, ever, put any user DLLs there. This is the primary cause of "DLL hell." What you should do is distribute them along with your application instead (e.g. in your .exe's working directory) or if the software has a run-time redistributable installation program (glew does not) ship that with it.
I am willing to bet good money you are running a 64-bit version of Microsoft Windows.
You are compiling a 32-bit application, and it will run in Microsoft Windows' 32-bit compatibility layer known as Windows on Windows. All 32-bit DLLs will be sourced from a separate location SysWow64 when running in the compatibility layer.
This can be confusing, as you would think that System32 means 32-bit... but for historical reasons System32 actually contains the DLLs for the native version of Windows (32-bit on Win32 and 64-bit on x64).
Nevertheless, do not install glew32.dll to SysWoW64 either :)
Since you mentioned in comments that you do not understand what "linking against glew32s.lib" means, I will tell you simply that this line in your header file is causing the linker to use the DLL version of glew:
#pragma comment (lib, "glew32.lib")
This is an ugly hack for the Microsoft Visual C++ compiler that tells the linker to add this as a dependency. It is not understood by other compilers (e.g. g++), but if your software is always going to be compiled with Visual Studio you can continue to use it.
To change your software to use the static (non-DLL) version of glew, simply replace that line with this:
#pragma comment (lib, "glew32s.lib")
Now you do not need to distribute a DLL along with your program and this whole problem effectively disappears.
I have been working on a VS 2005 project and have successfully generated an exe file which works fine on my system. However when I tried to run it on some other pc it didnt run. It throws up the error message "the system cannot run the specified program". Can someone tell me how to make my code immune to such message i.e. system independent?
platform used: Windows XP, VS 2005
the extension of all my code files is cpp but I know only c and thats what I wrote inside them.
I have seen before exe created on Windows Sp1 not working on SP2 and problems such as that.
This should help you perhaps.
I've seen this when you run on a different version of Windows that doesn't have some DLL you depend on. The easiest thing to do is statically link the C runtime (that's the usual culprit) and use depends.exe to see if there are any others.
You will almost certainly need to create an installer that installs your executable and any non-OS-included DLL's it relies upon. It is not always possible or desirable to statically link all dependencies. You can in many cases simply copy the DLL's to the same folder as the executable.
By default, even the C/C++ standard library is provided by a DLL. While the MSVCRT.DLL used by VC++ 6 is included with the OS since later editions Win95, the MSVCRT required by VS2005 is not included with XP installations (other versions I do not know). The run-time support is included VC redistributes package. You may need to arrange for your installer to include that installation, or you could be more selective is you know your dependencies.
Some Win32 API calls if you are using them are dependent on the OS version (check the documentation), but if you built and rin it on XP, it should normally work of any subsequent version of Windows. You need to define various API version macros if you want to extend support to earlier versions of Windows (which seems unlikley).
You might need to install the VS 2005 redistributables on the other machines, depending on how you have compiled your program.
I have written something that uses the following includes:
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <commctrl.h>
This code works fine on 2 machines with the Platform SDK installed, but doesn't run (neither debug nor release versions) on clean installs of windows (VMs of course). It dies with the quite familiar:
---------------------------
C:\Documents and Settings\Someone\Desktop\DesktopRearranger.exe
---------------------------
C:\Documents and Settings\Someone\Desktop\DesktopRearranger.exe
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
---------------------------
OK
---------------------------
How can I make it run on clean installs? Which dll is it using which it can't find? My bet is on commctrl, but can someone enlighten me on why it's isn't with every windows?
Further more, if anyone has tips on how to debug such a thing, as my CPP is already rusty, as it seems :)
Edit - What worked for me is downloading the Redistributable for Visual Studio 2008. I don't think it's a good solution - downloading a 2MB file and an install to run a simple 11K tool. I think I'll change the code to use LoadLibrary to get the 2 or 3 functions I need from comctl32.dll. Thanks everyone :)
Use Dependency Walker. Download and install from http://www.dependencywalker.com/ (just unzip to install). Then load up your executable. The tool will highlight which DLL is missing. Then you can find the redistributable pack which you need to ship with your executable.
If you use VS2005, most cases will be covered by http://www.microsoft.com/downloads/details.aspx?FamilyId=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en which includes everything needed to run EXEs created with VS2005. Using depends.exe you may find a more lightweight solution, though.
Common controls is a red herring. Your problem is that the Visual C++ 8.0 runtime - I assume you're using Visual Studio 2005 - isn't installed. Either statically link to the C/C++ runtime library, or distribute the runtime DLL.
You will have this problem with any C or C++ program that uses the DLL. You could get away with it in VS 6.0 as msvcrt.dll came with the OS from Windows 2000 up, and in VS.NET 2003 as msvcr71.dll came with .NET Framework 1.1. No more. Visual Studio 2005 and later use side-by-side assemblies to prevent DLL Hell, but that means you can't rely even on .NET 2.0 installing the exact version of C runtime that your program's built-in manifest uses. .NET 2.0's mscorwks.dll binds to version 8.0.50608.0 in its manifest; a VS-generated application binds to 8.0.50727.762 as of VS2005 SP1. My recollection is it used some pre-release version in the original (RTM) release of VS2005, which meant you had to deploy a Publisher Policy merge module if you were using the merge modules, to redirect the binding to the version actually in the released C run-time merge module.
See also Redistributing Visual C++ Files on MSDN.
I suspect it is trying to find a version of common controls that isn't installed. You may need a manifest file to map the version of common controls to your target operating system. Also, you may need to make sure you have installed the same VC runtimes that you were linked to.
Chris Jackson blog
EDIT: A little searching and I've confirmed (mostly) that it is the version of your VC++ runtimes that is to blame. You need to distribute the versions that you built with. The platform SDK usually includes a merge module of these for that purpose, but there is often a VCRedist.exe for them as well. Try looking Microsoft's downloads.
KB94885