Compiling and Distributing C Programs - c

I just finished a semester up of C programming for a class I'm in, and it has left me with some questions that I was hoping to get answered.
During my class we have been using GCC to compile C programs. This is all good and well, but I have a question about compiling.
What if I wanted to build a C program on Windows? There is no GCC. Is that what Microsoft Visual Studio is for?
Also, what if I wanted to compile a program and distribute it? What would I compile to distribute to other Window's users?
In summary, I know how to write C programs, but I just don't get how you would make a program to give to someone who doesn't have a C compiler and is basically computer dumb.
Thanks in advance,
Ryan

Generally you will need to do two things:
Compile your program into a stand-alone executable or binary.
a. On Windows this would be a win32 executable.
b. On Linux this would be an elf binary.
Create an installer package for your program.
a. On Windows you might use NSIS, Microsoft MSI, or InstallShield.
b. On Linux you would do well to use a packager for the distribution you want to target.
Anecodtally, it is very easy to utilize Eclipse CDT and NSIS to develop C and C++ software on Windows without needing to pay any license fees.
Eclipse CDT: http://eclipse.org/cdt/
Starter Guide: http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx
NSIS: http://nsis.sourceforge.net/Main_Page
Note that if you use Visual Studio then you will also need to compile in release mode and distribute the Visual Studio CRT or .NET runtime(s). It depends upon how you link to the standard library provided by your compiler.

you can get GCC for windows....
but, Visual Studio is probably a better choice.
Once you have built it, you can use something like Wix or InnoSetup to make an install program for it.

Related

Visual Studio Code does not include C header files

I recently downloaded Visual Studio Code to begin learning the C programming language. I installed the program as well as the C extension. However, when I tried to create the "Hello, World!" program, it would not run, and in the Problems menu it did not recognize the stdio.h header file, saying that I need to update my includePath. I have not been able to find any stdio.h file on my computer to link to. Do I need to download the C library files (even though I have read they should be included with the compiler), and if so, where can I find them? Or is there another solution? Thanks, and sorry if this is a stupid question, I am new to this.
I think you might be confusing VS Code with the VS IDE.
VS Code is a source editor only; that is to say that it's basically just a glorified text editor. It has the ability to load extensions and open a shell to compile the code, and there are a few extensions that let you debug the code itself, but they can be tricky to get setup and installed to work well with C/C++ code. VS Code does not have a compiler/assembler/linker nor the requisite headers or SDK's as that is up to you (the user) to install and then point to those in your settings file.
The Visual Studio IDE, on the other hand, is a complete integrated development environment that also includes the system headers and SDK's for Windows, as well as the binaries to properly compile, link and assemble your code into a binary for a Windows system (cross platform is possible as well). The Visual Studio IDE comes in many different flavors with the latest being VS 2017.
If you wish to stick with VS Code, you'll need to grab a compiler and the appropriate header files for the system you're targeting. If you wish to just stick with Windows for now, you can grab the Windows 7 SDK here or the Windows 10 SDK here .. you could even grab both and just reference the one you wish when you want. Note that the Windows 7 SDK includes the Microsoft C/C++ compiler, alternatively you can download the MSVC compiler from their Build Tools site.
There's also Cygwin in which you can use the GNU compiler, and of course Clang, which can be referenced in both VS Code and the VS IDE.
I hope that can help.

How to compile and execute C program on Visual Studio 2012 for Windows 8?

I was looking for a C compiler for Windows 8 and then came to know that I can compile C programs on Visual Studio.
Microsoft offers a walkthrough for the same, but I don't like it since it includes writing program in text editor and use of command prompt frequently, I am looking for more like a Turbo C++ interface.
Is there anyway I can run and compile programs directly in Visual Studio 2012 for windows 8 itself?
Or if that's not possible, what alternatives I have for windows 8?
From the page you posted:
By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code.
Now create any C++ project type you want and when you add the files, ensure they end in .c and you are done.
Since you asked for alternatives (not clear if you meant even alternative IDEs and/or compilers):
You could try the free Code::Blocks IDE which has support for MINGW, which includes a port of GCC (Gnu Compiler Collections) for Windows. An alternative, and sometimes easier to install, port of GCC based on MINGW is TDM-GCC. Code::Blocks can also be configured to work with other toolchains.
An advantage of using GCC is that it is the default compiler for Linux systems, so if you will happen to code for Linux too, you could "reuse" your knowledge of the GCC compiler you used on Windows.
Another alternative IDE could be eclipse, with its CDT extension, aimed at C/C++ development (can be configured to work with GCC or with many other toolchains). Much heavier than Code::Blocks, but with much more features.
you can use visual studio as TURBO C++
But here
if you want to compile single file
create program.c
file->new->c++file->open
then write c code and save it with extension .c
Now you need to create new project
and file->new->project
add program.c to this project.
and compile the project By using build->compile. before that change compile as with the
project->properties.
The last time I used Turbo C++ (in the early 90s), it was an IDE just like Visual Studio.
Both Turbo C++ and Visual Studio offer command line tools.
From the start menu, find the Visual Studio tools menu, there should be a command line shortcut there that allows you access to the command line (cl.exe) tools.
If you have makefiles, then you can use nmake rather than make.

debug C for UNIX API on Windows 7 with Cygwin?

I am just learning about Cygwin, and it appears to make possible to write C code against the UNIX API, and then have it run on Windows, provided you build it in the Cygwin environment.
I have gotten accustomed to the Visual Studio IDE and debugging tools, so wanted to ask: is it somehow possible to write and build C in Windows, and then debug it with Visual Studio, with the help of Cygwin?
No, because the VS debugging tools (for the most part) depend heavily on it being compiled using the MS C compiler, rather than GCC.
So if you manage to bootload it in, you won't get any of the more useful debugging features VS offers.
The closest alternative to Visual Studio that supports GCC is Eclipse.
Visual Studio isn't an option for your case because the VS collection of tools are designed to work with code compiled using the VS C compiler and not GCC. In lieu of Visual Studio, I suggest Codelite. It's designed specifically as a cross-platform IDE that will be familiar to developers that have migrated from Visual Studio. It will of course handle GCC or Clang.
In comparison to CodeBlocks (another potential IDE you can use), Codelite has a large number of features that are slightly improved, but it does have a few that are worth mentioning individually.
Clang driven code-completion and code tagging. This is separate from the compiler, so even when compiling with GCC the IDE can provide you with Clang-based features. As a word of caution, Clang supported features are not yet entirely implemented. For instance, Clang code suggestions aren't present, and code-completion doesn't yet work for Objective-C.
Partial support for Objective-C out of the box. CodeBlocks needs to be properly setup to correctly handle Objective-C projects, while Codelite can handle them without any modifications. I say partial support for Objective-C because of the aforementioned missing code-completion for Objective-C methods and classes.
Much higher quality build error output window; catalogues all build errors and warnings by message, file and project. The only thing I can directly compare it to is the build error output window in Xcode.
My suggestion is to try both IDEs and decide on which will better suit your needs.
It is actually possible to debug UNIX apps with Visual Studio. See Utilities and SDK for Subsystem for UNIX-based Applications.

Create a C program in Windows

I want to create a small C program and I would like to use the Windows command prompt to compile and run it. Can anyone suggest to me how to install a C compiler that works with the command prompt and the way to use it? How do I install the compiler, compile the code and run the program?
Download Visual Studio Express 2010 C++. From the File menu, choose New, then Project. Under Project Types, expand the tree view to Visual C++ -> General, then choose the template for Empty Project. Give it a name and a location. Click OK. Type in some C code, then Build and Run it.
It's a fairly simple tool to use, so I'd recommend you just go ahead and try it out.
There's several compilers available for Windows. Two popular ones are Microsoft Visual C++ and MinGW.
Using Visual C++, you can compile a program like so:
cl /Femyprog.exe myprog.c
Using MinGW, you can compile a program like so:
gcc -o myprog.exe myprog.c
Most programmers don't use command prompts to compile very much any longer. We use IDE's instead, because they're a hell-of-a-lot more convenient. Having said that there's no reason why you can't use the command prompt to "manually" execute the compiler which underlies, say, Microsoft Visual Studio.
So... If I where you I'd start by downloading Visual Studio 2010 C++ Express Edition from Uncle Bills Funny Farm. Note that C++ IDE (and compiler, or course) supports the old ANSI-C language as well as C++... in fact C++ is a "superset" of ANSI-C.
Your other options are a bit limited on Windows. I believe that GCC: GNU's C++ Compiler works on Windows... but it's "got a few issues" which nobody is any particular hurry to fix, simply because by far the majority of the GNU boys are running Linux, and they sort-of look down on Windows as "an interesting experiment [which failed]".
Cheers. Keith.

Good IDE/compiler for simple C dll's

I'm trying to disassemble a C/C++ DLL, and have made some progress, but I would like to create my own C DLL with the same function the original exports, and compare disassemblies.
Visual Studio adds to much crap, and when I remove the crap and build my project, the expected DLL is missing.
I need a lightweight, preferably IDE, tool to edit and build very simple C libraries.
Take a look at Code::Blocks
I need a lightweight, preferably IDE, tool to edit and build very simple C libraries.
I have found that one of the best ways to do integrated C-only Win32 development is using the freely available Lcc Win32 Compiler which comes with a built-in IDE, including resource editor.
In fact, it is really very lightweight and can be run from a USB stick with some manual tweaking.
It's indeed a really small download of just 6 mb and you can even download an optional Win32 API help file which is really useful while doing development.
The compiler also comes with a C tutorial, as well as good user documentation detailing how to use the integrated Win32 resource editor "wedit", there's also an advanced manual about more complex development tasks.
Dev-C++ is a nice and fast IDE which works well with MingW.
But it's all been asked and answered before ...
MinGW adds its own crap. Install your VC express properly and save yourself a lifetime of trouble.
Btw, you don't need to use Visual Studio for its compiler or vice versa. The oddity of missing a build dll is probably because you are not looking at the right path.
If you are building C DLLs you really would benefit from its command line toolset and utilities, sdks, easy config etc. MS lock-in proprietary extensions are widely used (in context of you trying to emulate another dll), and last thing you need is chasing cross compiler issues..
GCC + any text editor such as VIM is a very light alternative.
For Windows Development, all you need is inside MinGW
Edit: If you are in dire need of an IDE you can also use the MinGW tools from Eclipse with the CDT plugin. Although it adds weight to the solution because of the installation of Eclipse, this is what I really use to build my small DLLs (JNI wrappers in my case).
You can setup your small and direct makefiles or let Eclipse do it automatically for you and concentrate only on the source files (*.h, *.c).
The best part of using this approach instead other IDE is that you do not need Eclipse to further build the DLL, since the underlying project files generated are standard ones directly usable by integrated dev inside MinGW (or any Unix distro) such as make, configure, automake, and so on.
I'll second the vote for Code::Blocks, it's what I use (despite having VS 2008 installed as well). It is very simple and lightweight but has basically all the features you'd expect out of an IDE. It comes with several predefined project templates for all kinds of C and C++ development, including templates for DLLs.
Download the version that includes MinGW and you get a complete lightweight IDE ready to start compiling. You can also easily configure it to use the Visual Studio compiler instead of gcc if you prefer.
try Open Watcom. A cross-platform product, well-supported by the community, lets you develop in DOS, Windows, OS/2 etc for a lot of platforms. Version 1.8 was released recently. Has a light-weight IDE indeed

Resources