Problem creating an exe from C - c

I've made a small application in C with Netbeans.
I've ran the application in Netbeans and it created an exe.
I used that exe and it worked fine on my comp but when I move it to other comp it says:
"This application failed to start because cygwin1.dll was not found. Re-installing the application may fix this problem."
How can i create the exe so that it runs anywhere?

The problem is you're using Cygwin GCC to compile your code. Cygwin provides a unix-like environment
if you're not doing anything Unix-y you can recomplie -mno-cygwin - see Can you statically compile a cygwin application?
if you are using Unix calls you'll need to distribute cygwin1.dll along with your app
or you can recompile with a different compiler, e.g. a GCC that targets mingw32 not cygwin, or one of the free (as-in-beer) Microsoft compilers from the platform SDK or Visual Studio Express downloads.

Related

While Coding in C (MinGW) fatal error: sdkddkver.h: No such file or directory

I have just installed MinGW
This is the code
#include<stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
I am getting this error:
In file included from c:\mingw\include\_mingw.h:73:0,
from c:\mingw\include\stdio.h:56,
from main.c:1: c:\mingw\include\w32api.h:59:23: fatal error: sdkddkver.h: No such file or directory #include <sdkddkver.h>
^ compilation terminated.
This looks like a problem with your mingw install, missing dependencies, or environment. Your C code is 100% correct so it's not really a "C" language question at all.
Typically... the only thing that REQUIRES mingw is compiling pre-existing Linux code for distribution on Windows.
If that's really what you need you could:
Try installing Windows SDK to see if it resolves. The missing header: sdkdkver.h is part of Windows SDK (per a very quick google search).
Uninstall mingw & re-install with different instructions.
I've had decent success with cygwin in the past. Looks like MSYS2 is a viable alternative that's more dedicated to building windows "native" SW.
Could dig through mingw documentation on environment variable setup. Maybe missing something there.
Alternatives if you DON'T need to compile + distribute existing Linux source for Windows:
Target Windows directly. Free versions of Visual Studio support compiling C or C++ code. So if you're writing FOR WINDOWS, this is your best bet.
Could use Windows Subsystem For Linux ... if you're just looking run Linux SW or do Linux SW development on a natively windows machine.

Why does MinGW on Windows not need to link statically?

I've installed MinGW on my Linux machine and installed the MinGW package, however, I noticed that I can't run my program on Windows machines that don't have MinGW, I looked it up and soon found that the solution to this is to link statically. This worked, but it's still annoying to have to statically link everything and doesn't make much sense. I noticed that on my Windows machine where MinGW was installed I could compile a program without statically linking anything and the program would run successfully on any Windows machine regardless of whether it had MinGW installed or not.
My Linux box is running Arch Linux and Installed the mingw-w64-gcc AUR packages if that info helps at all.
Linux and Windows shared libraries / dynamically linked libraries are similar in how they get discovered. Your mingw program works in windows that has mingw installed because the installation likely added DLLs to your search path. Check out this article on DLL search order.
When you statically link, all that library code gets included in your executable.
If you want to share your mingw program with friends, then you need to also install all the shared libraries it uses in their search path. You can use sysinternals listdlls (or other tools) to find your dependencies, and include them in the same directory as your exe or install them to a library path (see the search order article).
You can also check out this article; How do I find out which dlls an executable will load? as it has lots of other options.

Switch C project configuration in Eclipse between Windows and Linux

I installed Eclipse with CDT plugin. I created a simple TCP client software that runs on Windows. I can open the project on Ubuntu also. I'd like to change build configuration in order to create Linux executable. Is it possible to create executable for the operating system that the project is compiled. I mean if I compile the project on Ubuntu, there should be Linux executable and if I compile the project on Windows, there should be Windows executable. Is it possible?
It is possible. When you are creating a Project in Eclipse, you are provided with two build options. One debug and one release. The release build will create the executable for the OS in which it is run.
Good Luck!

Compile file in linux and run in windows

I start to learn c and c++ programming and I write it in Linux.
Can I make binary file with g++ and run it as exe in window 7? or i need to compile the code in windows again?
You can use a mingw cross compiler to build windows binaries in linux. In Ubuntu (and I guess other Debian variants as well) the package is called mingw32. You then have a cross compiler under the name i586-mingw32msvc-g++ (or similar). For building simple command line programs without library dependencies this is an OK solution.
If you need more then this I'd recommend you use MXE (M cross environment). MXE installs its own cross compiler and can build many libraries for you so you don't need to care about how to build the library dependencies.
For example the OpenSCAD project (a 3D CAD program that is using Qt for its GUI) is using MXE for building the Windows releases. See this page on the OpenSCAD wiki for a description of the build process.

How to compile a C program?

I haven't done C in a long time. I'd like to compile this program, but I have no idea how to proceed. It seems like the makefile refers to GCC a lot and I've never used GCC.
I just want an executable that will run on windows.
You may need to install either cygwin or mingw, which are UNIX-like environments for Windows.
http://www.mingw.org/
http://www.cygwin.com/
When downloading/installing either cygwin or mingw, you will have the option of downloading and installing some optional features; you will need the following:
gcc (try version 2.x first, not 3.x)
binutils
GNU make (or gmake)
If it requires gcc and you want it to run on Windows, you could download Cygwin.
That's basically an emulator for GNU/Linux type stuff for Windows. It works with an emulation DLL.
http://www.cygwin.com/
In order to compile this program you need a C compiler. It does not have to be gcc, although you are already given a makefile set up to use gcc. The simplest thing for you to do would be the following:
Install cygwin
Open the cygwin command prompt
go into the directory where you have your makefile
type 'make'
That should compile your program
If you are not comfortable with using command line tools then you can download the free version of MS Visual Studio and import the source files into a new Visual Studio project. This way you would not need to install cygwin and use gcc, but you would need to know how to create projects and run programs in Visual Studio.
You almost certainly don't need all of cygwin to compile using gcc. There are plenty of standalone gcc clones for Windows, like gcw.
If it's reasonably portable C code (I haven't looked at it), then you may be able to just ignore the included Makefile and feed the source into whatever compiler you do want to use. What happens when you try that?
Dev-C++ provides a simple but nice IDE which uses the Mingw gcc compiler and provides Makefile support. Here are the steps I used to build the above code using Dev-C++ (i.e. this is a "how-to")
After downloading the source zip from NIST, I
downloaded and installed the Dev-C++ 5 beta 9 release
created a new empty project
added all the .c files from sts-2.0\src
Then under Project Options
added -lm in the Linker column under Parameters
added sts-2.0\include to the Include Directories in Directories
set the Executable and Object directories to the obj directory under the Build Options
and then hit OK to close the dialog. Go to Execute > Compile and let it whirl. A minute later, you can find the executable in the sts-2.0\obj directory.
First, there is little chance that a program with only makefiles will build with visual studio, if only because visual studio is not a good C compiler from a standard POV (the math functions in particular are very poorly supported on MS compilers). It may be possible, but it won't be easy, specially if you are not familiar with C. You should really stick to the makefiles instead of trying to import the code in your own IDE - this kind of scienfitic code is clearly meant to be compiled from the command line. It is a test suite, so trying things randomly is NOT a good idea.
You should use mingw + msys to install it: mingw will give you the compilers (gcc, etc...) and msys the shell for the make file to run correctly. Contrary to one other poster, I would advise you against using gcc 2 - I don't see any point in that. I routinely use gcc 3 (and even 4) on windows to build scientific code, it works well when the code is unix-like (which is the standard platform for this kind of code).

Resources