Codeblocks compile and run works but clicking on exe doesn't - c

I am new to C programming. I downloaded Code::Blocks to try. I had already installed the gcc compiler and so that's what codeblocks is set to use. I wrote a simple program and compile and ran it. It ran fine when I ran it from inside Code::Blocks but when I tried to double click the .exe it said
"The program can't start because libgcc_s_dw2-1.dll is missing from your
computer. Try reinstalling the program to fix this problem."
Why is it that it works when I run it in Code::Blocks but not when I click on the file?
BTW, here are my #includes.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

I think author already solved his problem, but I just want to add my solution.
To use your executable file you need to follow these steps, to configure your project:
Project -> Build Options
Select correct target or project in left hand panel
Tab: Linker Settings
Box: Other linker settings
Enter follow linker options one per line:
-static
-static-libgcc
-static-libstdc++
Also,it could be helpful to add (..\mingw\bin) path to the project search directories.

Did you try and run you're program from the terminal? If not, do so, because then you won't have the problem that you compiler won't be found.
In your home directory in the terminal call to compile:
gcc yourprogram.c -o yourprogram.exe
./yourprogram.exe arg1 arg2
Second one is to run; arg1 and arg2 would be command line arguments you pass to the program. (This works on Mac and Linux, I have 0 experience on Windowsterminal)
Anyway, if you really want to learn how to program, then you should learn how to work with the terminal; then you'll never have to worry about GUI-Problems ever again, which is what you're now doing.

I had the same problem: running the exe inside CodeBlocks it was working, but running it inside cmd terminal gave the error.
I solved copying MinGW libs inside c://windows/SysWOW64(for 64bit windows).
I attach the zip with libs
https://3.sharebylink.com/1/?wjiteTTdXR8k or
https://files.fm/u/b6wqqwdy
Hope this helps!

I had the same problem and after about 4 hours of fighting with it, I finally got it figured out.
All you have to do is click project at the top of the screen, then build options, then checkmark Static libgcc, Static libstdc++, and static linking. click ok and then rebuild your project.
Hope that helps.

Related

Equivalent of 'make' command for CodeBlocks?

I am using Codeblocks in Windows 10. Earlier I used to compile only 1 file, so I would just press the 'Build' and 'Run' button on codeblocks.
But, this time there are separate files I need to compile separately (to .o format) and then link to form a single executable file which I need to run. How can I do this in CODEBLOCKS? (In UNIX/LINUX systems, I know this is the 'make' command; but I don't know how to do it here?)
Can anyone help me? I tried reading some help pages on CodeBlocks on the internet, but they were so complicated, I gave up.
make isn't a compiler, and neither is CodeBlocks. make is just a command that runs other commands from a Makefile. The actual command that gets run is something along the lines of gcc a.cpp b.cpp, and it's the same command (or similar enough) that gets run when you build inside CodeBlocks. CodeBlocks should automatically build and link all of the source files that you add to your project. If you aren't seeing this happening, make sure you add them to the project inside of CodeBlocks and don't just put the files in the directory.

Struggling to get PortAudio to Work with MinGW

I have the MinGW install previously working fine with MSYS. They are installed properly and functioning just well.
I installed the PortAudio library and did the install and got the success message after:
./configure
make
make install
When I try to compile samples:
c:\c>gcc patest_mono.c -o pa.exe
patest_mono.c:50:23: fatal error: portaudio.h: No such file or directory
#include "portaudio.h"
^
compilation terminated.
I'm new. I have a feeling I might be doing something fundamentally wrong with the way I'm trying to create the exe from compiling. It's been somewhat of a puzzle quest so far, but I've tried to figure it out and think I am close but completely missing something.
PATH variable ?
In the PortAudio MinGW build instructions I noticed
"The above should create a working version though you might want to
provide '–prefix=<path-to-install-dir>' to configure. "
I've tried adding C:\MingW\PortAudio into the user path. Doesn't work.
I've also tried running the commands in Bash and they come back with an error message "No Rule to make target 'paexpink'" either with the make command, and with gcc .c -o .exe I just get the same error message as compiling straight from the cmd prompt.
I found another source on stack overflow thread with no answers, but the user had commented that http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio provided them a solution but I tried installing the 5 cpython binaries and under the assumption I did it right, it didn't work either.
Thanks for your help,
Julian
To build and install portaudio, you need to add -prefix=/c/<"path to base of the MinGW directory"> to the ./configure line.
For example: ./configure -prefix=/c/MinGW/
then continue the installation by doing
make
After that, do the
make install
and that should install the portaudio files into MinGW.
After it has finished installing, you need to add -lportaudio to the compile command whenever you compile any programs that you want to use PortAudio in.
For example: gcc -o test test.c -lportaudio
I just figured out how to do this today, so I may have accidentally forgotten a few steps.

Cannot Compile C code with MinGW

I am currently trying to compile and run C code on a Windows 8 machine and have installed MinGW so that I could do so. However, whenever I run the command to compile, I am told that the I: drive is missing and when I cancel the program tell me that libgmp-10.dll is missing. Here is the exact command I am using to try and compile:
"C:\MinGW\bin\gcc.exe" helloworld.c -o helloworld.exe
This leads to those two dialog boxes.
The first just says to insert the missing drive I. If I click Try Again, nothing happens and if I click the other two options, a second dialog box appears.
The second says that I am missing the libgmp-10.dll. I know for a fact that the dll exists in the same folder in which gcc.exe resides, and that the place where I am running these files from is off of the C drive drive. I have added "C:\MinGW\bin" to the path variable like this question's answer suggests, but no dice.
TL:DR - Can use gcc from MinGW to compile C code. Adding bin to path did not solve 'missing dll problem' and dll exists in same folder as gcc.exe
Try reinstalling MingGW. It worked to me when i was getting trouble in Windows 8.

Source file not compiled Dev C++

I just installed Dev C++ and I am learning C programming.
the code i used was
#include <stdio.h>
int main()
{
printf("Hello world");
getch();
}
I saved it as a .c file. When I compile it works fine, but when I compile and run it says source file not compiled. So I googled buncha things and came across this video on youtube which shows you how to fix it. I also saw other forums on google which suggest the same thing... However, after doing whats asked, Now I can't even compile my code. I get this error
Compiler: Default compiler
Executing C:\Dev-Cpp\bin\gcc.exe...
C:\Dev-Cpp\bin\gcc.exe "C:\Users\ubaid\Documents\C\Untitled1.c" -o "C:\Users\ubaid\Documents\C\Untitled1.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
gcc.exe: Internal error: Aborted (program collect2)
Please submit a full bug report.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
Execution terminated
I have also used what is asked on this link, and still no luck..
http://learntogeek.com/miscellaneous/solved-source-file-not-compiled-error-in-dev-cpp/
I am using windows 8
I was having this issue and fixed it by going to:
C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2
, then deleting collect2.exe
Install new version of Dev c++. It works fine in Windows 8. It also supports 64 bit version.
Download link is http://sourceforge.net/projects/orwelldevcpp/ .
I guess you're using windows 7 with the Orwell Dev CPP
This version of Dev CPP is good for windows 8 only. However on Windows 7 you need the older version of it which is devcpp-4.9.9.2_setup.exe
Download it from the link and use it.
(Don't forget to uninstall any other version already installed on your pc)
Also note that the older version does not work with windows 8.
This maybe because the c compiler is designed to work in linux.I had this problem too and to fix it go to tools and select compiler options.In the box click on programs
Now you will see a tab with gcc and make and the respective path to it.Edit the gcc and make path to use mingw32-c++.exe and mingw32-make.exe respectively.Now it will work.
The reason was that you were using compilers built for linux.
You can always try doing it manually from the command prompt. Navigate to the path of the file and type:
gcc filename.c -o filename
I found a solution. Please follow the following steps:
Right Click the My comp. Icon
Click Advanced Setting.
CLick Environment Variable. On the top part of Environment Variable Click New
Set Variable name as: PATH then
Set Variable Value as: (" the location of g++ .exe" )
For ex. C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
Click OK
This error occurred because your settings are not correct.
For example I receive
cannot open output file Project1.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [Project1.exe] Error 1
Because I have no permission to write on my exe file.
After some investigation, and with Dr.Topaz's help, I have learned that you will want to confirm that the program set for g++ in the Compiler Options really does compile the source code. In my case, the C:\Dev-Cpp\bin\g++.exe program did not create an exe, but the C:\Dev-Cpp\bin\c++.exe program did. Either program appears to be intended to take the same arguments and options as GNU g++. I would love to find an actual doc on the Dev-C++ compiler programs, but I have not so far.
You can test the compiler program with a simple example like this:
C:\Dev-Cpp\bin\c++.exe hello.cpp -o hello.exe
Currently in 2021, the Dev-C++ site invites you to download either original Dev-C++ or a newer fork by a group named Embarcadero.
I decided to try the Embarcadero version and the experience was slightly better. The UI is still a tad dated, but the g++.exe program it came with was able to compile programs without issue. Again, take note of where the program is being installed, but in my case, the Embarcadero compiler programs were in C:\Program Files (x86)\Embarcadero\Dev-Cpp\TDM-GCC-64\bin.
Both original Dev-C++ and Embarcadero come with mingw-32 versions of the compiler programs that from what I see do work in a Git Bash console, with slight differences such as not recognizing a default locale when using the command std::cout.imbue(std::locale("")).
I faced this similar error, and none of the solutions worked.
so I tried to download the latest version from here, https://www.bloodshed.net/
I rerun the program.
and everything is now working correctly.
I was facing the same issue as described above.
It can be resolved by creating a new project and creating a new file in that project.
Save the file and then try to build and run.
Hope that helps. :)

Using Cygwin to Compile a C program; Execution error

I'm enrolled in a masters computer science course. The course is using C and the instructor wants us to use Cygwin to compile programs if we are using windows.
I've downloaded and installed Cygwin and I've ensured that I've installed the GCC compiler.
But I don't know where to go from here. I need to compile a single source file that has a basic include.
#include <stdio.h>
Lets assume the file is on my desktop (it is not, but for the sake of argument). How do I navigate to the desktop from the bash shell? I assume once I've navigated to the correct location in bash, I simply execute:
gcc myProgram.c -o myProgram
Update: Following different instructions posted below, I was able to compile the program; I thank you for that. But when I execute the resulting binary I get the following. How can I compile or execute this program so I don't get the error? Again, thank you.
This application has failed to start because cygwin1.dll was not found. Re-installing the application may fix this problem.
when you start in cygwin, you are in your $HOME, like in unix generally, which maps to c:/cygwin/home/$YOURNAME by default. So you could put everything there.
You can also access the c: drive from cygwin through /cygdrive/c/ (e.g. /cygdrive/c/Documents anb Settings/yourname/Desktop).
Regarding your updated question about the missing cygwin1.dll.
From the Cygwin terminal check,
ls /usr/bin/cygwin1.dll
If it is not present (I doubt that), your installation is not properly done.
Then, check your path with,
echo $PATH
This will give : separated list of paths. It MUST contain /usr/bin. If you find that missing add it with,
export PATH=/usr/bin:$PATH
Finally,
I hope you are using Cygwin from the cygwin terminal (the little green+black icon installed with Cygwin), or MinTTY (if you installed that).
And, you have not moved the compiled EXE to a different machine which does not have Cygwin installed (if you do that, you will need to carry the cygwin1.dll to that machine -- keep it in the same folder as the compiled EXE).
Just to summarize, here are some commands that navigate to a directory and compile code using Cygwin and Windows Vista:
Start a Cygwin shell.
At the prompt, use cd to change to the appropriate directory:
$ cd /cygdrive/c/Users/nate/Desktop
Use ls to list the files in the directory:
$ ls
prog.c
Use the gcc command to compile a file in this directory:
$ gcc prog.c -o prog
If you don't see any errors, you should be able to run the resulting program:
$ ./prog
Update:
For the "Cygwin1.dll not found" error, I like Nik's answer. You might also check out this related post about cygwin1.dll not found, which suggests adding c:\cygwin\bin\ to your Windows PATH.
There are instructions on how to change the Windows PATH variable for Windows XP, and on Vista I think it's similar.
Go to Control Panel -> System
Select Advanced System Settings
Click on the Advanced tab
Click on Environment Variables
Under System Variables, find the Path entry and click Edit
Add c:\cygwin\bin to the list, making sure to separate it from any previous items with a semicolon
Look for (that is, cd to)
/cygdrive/c/
that will usually be your C:\
Also look at Using Cygwin, the Lifehacker introduction (June/2006) and, this biomed page at PhysioNet.
Regarding the cygwin1.dll not found error, a solution I have used for at least 8 years is to add the Cygwin bin directories to the end of my %PATH% in My Computer -> Properties -> Advanced -> Environment Variables. I add them to the end of the path so in my normal work, they are searched last, minimizing the possibility of conflicts (in fact, I have had no problems with conflicts in all this time).
When you invoke the Cygwin Bash Shell, those directories get prepended to the %PATH% so everything works as intended in that environment as well.
When not running in Cygwin shell, my %PATH% is:
Path=c:\opt\perl\bin; \
...
C:\opt\cygwin\bin; \
C:\opt\cygwin\usr\bin; \
C:\opt\cygwin\usr\local\bin;
This way, for example, ActiveState Perl's perl is found first when I am not in a Cygwin Shell, but the Cygwin perl is found when I am working in the Cygwin Shell.
If you are not comfortable with bash, you can continue to work in a standard windows command (i.e. DOS) shell.
For this to work you must add C:\cygwin\bin (or your local alternative) to the Windows PATH variable.
With this done, you may:
1) Open a command (DOS) shell
2) Change the directory to the location of your code (c:, then cd path\to\file)
3) gcc myProgram.c -o myProgram
As mentioned in nik's response, the "Using Cygwin" documentation is a great place to learn more.
If you just do gcc program.c -o program -mno-cygwin it will compile just fine and you won't need to add cygwin1.dll to your path and you can just go ahead and distribute your executable to a computer which doesn't have cygwin installed and it will still run. Hope this helps
Windows path C:\src under cygwin becomes /cygdrive/c/src
Compiling your C program using Cygwin
We will be using the gcc compiler on Cygwin to compile programs.
1) Launch Cygwin
2) Change to the directory you created for this class by typing
cd c:/windows/desktop
3) Compile the program by typing
gcc myProgram.c -o myProgram
the command gcc invokes the gcc compiler to compile your C program.
You might be better off editing a file inside of cygwin shell. Normally it has default user directory when you start it up. You can edit a file from the shell doing something like "vi somefile.c" or "emacs somefile.c". That's assuming vi or emacs are installed in cygwin.
If you want to file on your desktop, you'll have to go to a path similar (on XP) to "/cygwindrive/c/Documents\ and\ Settings/Frank/Desktop" (If memory serves correctly). Just cd to that path, and run your command on the file.
Cygwin is very cool! You can compile programs from other systems (Linux, for example), and they will work. I'm talking communications programs, or web servers, even.
Here is one trick. If you are looking at your file in the Windows File Explorer, you can type "cd " in your bash windows, then drag from explorer's address bar into the cygwin window, and the full path will be copied! This works in the Windows command shell as well, by the way.
Also: While "cd /cygdrive/c" is the formal path, it will also accept "cd c:" as a shortcut. You may need to do this before you drag in the rest of the path.
The stdio.h file should be found automatically, as it would be on a conventional system.
This file (cygwin1.dll) is cygwin dependency similar to qt dependency.you must copy this file and similar files that appear in such messages error, from "cygwin/bin" to folder of the your program .Also this is necessary to run in another computer that have NOT cygwin!

Resources