Running a C program written in Visual Studio 2013 on other pc - c

Every time I write a C program using Visual Studio 2013 the .exe file only runs on my PC. When I copy that .exe file to other PC it doesn't run. But if I use Code Blocks IDE instead the .exe file runs in all PCs. Why? and how can I make a 'C program' written in 'Visual Studio 2013' run on every PC?

It's because of the 2013 runtime libraries1, you need to download the redistributable and install it into the target computer.
You can download it from here.
1The file is called msvcr120.dll if you compiled with the VS 2013 ("v120") platform toolset, and otherwise follows the pattern msvcrNNN.dll.

In your project settings, change the Runtime Library support to Multi-threaded (/MT) instead of the default, which is Multi-threaded DLL (/MD). This will cause your .exe to be statically linked, and it won't need to look for the runtime libraries on the target machine. (I think it's under C/C++ Code generation, but I don't have visual studio 2013 installed at that moment to verify that).
The resulting .exe will be bigger (because it has to link in all the parts of the runtime that you use), but it simplifies deployment on other machines - no need to install the redist package.

Related

How to target multiple versions of Windows

I am using visual studio 2017 and Windows 7 (sp1). I compiled a c program on my computer. But, On my friend's computer, it's not running. I don't want to share my source code. My friend uses windows 10. How can I compile my program to run on both computers.
Thank you!
To make a compiled deliverable that works on other machines in Visual Studio, what you need to do is:
Compile in Release mode (it is Debug by default)
Ship the appropriate Visual C++ Redistributable package with your executable
Ensure that the target architecture (x86, x64, ARM, or Itanium) is appropriate for your particular deliverable
Creating a setup wizard makes a lot of this easier.
Also note that Windows SmartScreen will by default not allow computers to run foreign, un-digitally signed programs acquired from the Internet.

How to compile zlib into a DLL on Visual Studio 2017?

I have a hard time trying to do something I think is really simple (I must not be the first one to want to do that). I use Visual Studio 2017 on Windows 7 to do some C code, and I need inflate/deflate for zip.
I search a little, and I found zlib. It seem to be exactly what I search: free, cool copyright, no patent and extensively used and tested in other project.
So, I start to download the latest version (zip of 1.2.11) and here I go, trying to "simply" get the DLL.
However, the documentation state that in order to compile "zlib1.dll", I have to use "./contrib/vstudio/vc..", with ".." the right Visual Studio. But I have Visual Studio 2017 and there are only "vc9" to "vc14", "vc14" being Visual Studio 2015.
The doc say that I have to use Microsoft Visual C++ 2015, and indeed, when I force open with vs2017, I have integrity error.
So I try to install MVC++ 2015, but then it say that I can't install it because I already have something (VS2017) installed.
Is there really no way to achieve something so basic, or there is knowledge that I don't know?
Open source projects can be a challenge to build as their support tends to lag well behind the latest versions of Visual Studio. This is one reason why Visual Studio now supports cmake directly.
That said, the easiest way to build zlib for Windows is just use a NuGet package. I personally use zlib-msvc14-x86 or zlib-msvc14-x64 which are binary compatible with VS 2015 Update 3, VS 2017, and VS 2019. They also provide a static library instead of a DLL.

Invoke cl (Visual Studio 2013) cross-compiler from CMD on 64bit Windows

I have downloaded the LiE software
http://wwwmathlabo.univ-poitiers.fr/~maavl/LiE/
Unfortunately, I work on Windows 7 (64 bit) but the code seems to only target 32-bit Linux platforms (i.e. there is only a Makefile that uses the GNU make + gcc).
My idea is to install the GNU make (and some other required tools) for Windows from GnuWin32 and adapt the provided Makefile to the Windows-environment by replacing gcc calls by calls to the VC++ 32-bit cross-compiler. However, when I try to invoke the cross-compiler from the command prompt, I get the error "The dll mspdb120.dll is missing". The question is: How do I invoke the cross-compiler from the command-prompt/GNU make for Windows without copying dlls around? Btw invoking the native 64 bit compiler goes off without a hitch by just calling the cl.exe by its fully specified name!
Thanks a lot!
P.S. I'm using MS Visual Studio Express 2013 and the native-compiler is stored here:
C:\Software\Development\Microsoft Visual Studio 2013\VC\bin\
The cross-compiler is, as expected, stored one level deeper:
C:\Software\Development\Microsoft Visual Studio 2013\VC\bin\x86_amd64
P.P.S.: I have tried to create a MS Visual Studio solution but the Makefile compiles three exe-files, the bison-parser is called externally + multiple source files are merged into a single object file -- the requirements that are extremely hard to implement using the VS-functionality -- so I have abandoned this futile endeavour.
From the Windows command prompt, run the command C:\Software\Development\Microsoft Visual Studio 2013\VC\bin\x86_amd64\vcvarsx86_amd64.bat. That will set up the PATH and other environment variables that need to be set to use the Microsoft compiler normally. You'll need to rerun this command every time you open the Windows command prompt.
You can also use a shortcut included with your Visual Studio 2013 installation that will run this script automatically while opening a command prompt. It's located in the Start menu under Visual Studio 2013 -> Visual Studio Tools -> VS2013 x64 Cross Tools Command Prompt. You can also find it at at C:\Software\Development\Microsoft Visual Studio 2013\Common7\Tools\Shortcuts\VS2013 x64 Cross Tools Command Prompt.lnk.

Can I execute vs2012 compiled binaries on win2k3?

I am compiling C projects with vs2012 ultimate on win2k8r2 machine.
But I want to execute same binaries on win2k3 server.
can I do it with modified setting in vs2012?
As far as i know, if you want to make native app built by vs2012 work on Windows xp and Windows Server 2003, you must have vs2010 installed.
There're some configurations to make vs2012 use vs2010's compiler to build apps.
When you compile your binary, linker will link you executable with runtime library. This runtime library can be different on win2k3 server and win2k8.
But, just try :-)
Also, you can set the compiler to use static linking in the project settings (Project -> Properties -> Config Properties -> C/C++ -> Code Generation -> Change "Runtime Library" to /MT or /MTd instead of the default /MD or /MDd)
As released at RTM, native applications built with Visual C++ 2012 would not run on Windows XP or Windows Server 2003 - they would only run on Vista or later.
However, Microsoft will release an update that supports Windows XP and Windows Server 2003 as targets (they will still be not supported as the development platform):
Targeting Windows XP with C++ in Visual Studio 2012

Where does VC++ 2008 linker find libraries?

I have VC++ 2008 C++ .DLL project that uses Opends60.lib (it is listed in Linker/Input/Additional Dependencies as "Opends60.lib")
I ported this project to VC++ 2010 (in different folder) and now link step fails with message:
Error 3 error LNK1181: cannot open input file 'opends60.lib'
So I figured I need to copy library from somewhere in 2008 project folder to 2010 project folder. Problem is - that library is nowhere to be found in 2008 project folder or anywhere on my hard drive!!! It is a mystery how 2008 project gets linked but somehow it does. Removing this library from 2008 project causes a bunch of unsolved externals, so it is found somewhere by linker.
Question: is there a way to find out where exactly linker from VC++ 2008 is finding this library?
In a nutshell - I used Windows Explorer (on Vista) to search for this file and it turns out by default it doesn't search in System and Program Files. More details is here:
https://superuser.com/questions/327699/windows-explorer-doesnt-search-system-or-program-files

Resources