I am trying to install C and C++ compiler on Windows 8.
I have already installed MinGW, downloaded and installed mingw32-base and mingw32-gcc-g++ packages and the other required packages, added to the user environmet Path the string "C:\MinGW\bin", and I also tried following this guide
http://www.mingw.org/wiki/Getting_Started
so after installation I created a new file named "fstab" containing "C:\MinGW /mingw" in C:\MinGW\msys\1.0\etc because it was only present the file named "fstab.sample".
After all this I typed on cmd : gcc sample.cpp -o sample.exe
and it doesn't work at all returning me an error:
gcc: fatal error: no input files
compilation terminated
But if I typed gcc --version it gives me gcc 4.9.3 etc...
so the packages are installed but I can't compile any of my programs
Are you in the correct directory in cmd when compiling?
You can navigate to the correct one with cd and check if your .cpp is there with ls
possibly some problem with folders. probably you are not compiling from source directory.
Check out this mingw distro by STL. It contains a few .bat files that open a cmd prompt with compiler in PATH. I use these for all my mingw installations. BAT files are to be placed in mingw folder:
mingwvars.bat
#echo.
#echo Setting up environment for using MinGW with GCC from %~dp0.
#set PATH=%~dp0bin;%PATH%
set_distro_paths.bat
#echo off
if not exist "%~dp0bin\gcc.exe" goto epicfail
if "%X_DISTRO%" == "nuwen" goto :eof
set X_DISTRO=nuwen
if exist "%~dp0git\cmd\git.exe" set PATH=%~dp0git\cmd;%PATH%
set PATH=%~dp0bin;%PATH%
goto :eof
:epicfail
color 4f
echo ERROR: You must run %~nx0 from the root of the distro.
echo Don't copy or move this batch file.
title ERROR
goto :eof
open_distro_window.bat
#echo off
if not exist "%~dp0bin\gcc.exe" goto epicfail
if "%X_DISTRO%" == "nuwen" goto :eof
set X_DISTRO=nuwen
if exist "%~dp0git\cmd\git.exe" set PATH=%~dp0git\cmd;%PATH%
set PATH=%~dp0bin;%PATH%
goto :eof
:epicfail
color 4f
echo ERROR: You must run %~nx0 from the root of the distro.
echo Don't copy or move this batch file.
title ERROR
goto :eof
It's a very common error when you are not in the current directory where your source files are residing.
So just navigate to the current directory and run the command it will compile the source code.
Related
Visual Studio Code 1.46.1
Operating system: MacOS 10.15.4 (Catalina)
VS Code Package used: C/C++, Code Runner
Problem: When I run a C++ code using Code Runner, a file with no extension automatically appear.
I would like to know what does this 'useless file' do, and how to make these files stop from spawning.
That is the executable file also called binary file. They are the executable like .exe in windows so it is very useful(as it is the output of source code). If you dont want to see that file in sidebar of vscode then there is a good answer to this question. Alternatively you can configure your build configuration file (located at .vscode in you working directory) and set the build path to somewhere else
You are using Code Runner extension on vscode then you can modify the execution command.
Go to Code-runner: Executor Map Setting
I did this:
"code-runner.executorMap": {
...
"c": "cd $dir && gcc $fileName -o ./temp/$fileNameWithoutExt && $dir./temp/$fileNameWithoutExt",
...
}
create a temp folder.
Now your temp folder will contain those unwanted files.
You can modify execution command like this for c++ also.
I'm running Windows 8.
I installed the MinGW compiler to the default C:\ directory using the GUI installer. I selected to install all the elements available in the Basic Setup package of the MinGW Installation Manager.
After the installation completed, I checked that "C:/MinGW/msys/1.0/etc/fstab" had the one line of C:/MinGW /mingw and an open line beneath it. I also created a shortcut to msys.bat in the Start menu.
Then I rebooted my machine.
I created a folder called "CompileBin" in the C:\ directory, so C:\CompileBin\ and then I placed my test.cpp file inside, so C:\CompileBin\test.cpp
I ran msys.bat and the console opened up. It showed:
MyName,#MyLaptopsName ~
$
I started to navigate to where my test.cpp is:
cd c:\CompileBin\
Now the prompt looked like this:
MyName,#MyLaptopsName ~
$ cd c:\CompileBin\
>
I entered the dir command to look around and got the response:
MyName,#MyLaptopsName ~
$ cd c:\CompileBin\
> dir
sh: cd: c:CompileBindir: No such file or directory
Okay, so I figured maybe the path wasn't set up.
I added PATH to the Environment Variables (because it was NOT originally there) and gave it the value C:\MinGW\bin;
I still get the same error.
Unix tooling requires forward slashes in path names. It is cd c:/CompileBin
I have just installed the CodeBlocks to compile c++ programs,
The path where this is installed is,
C:\Program Files\CodeBlocks\MinGW\bin
I have also added this path to the Environment Variables path,
The g++ command works fine from command prompt, inside this folder,
g++: fatal error: no input files
compilation terminated
but when i give the g++ command outside this folder, it gives me an error,
'g++' is not recognized as an external or internal command,
operable program or batch file
My question is, why i am getting this error, even after i have added the path to the environment variables ?
You have probably added the wrong path.
I am using Borland C++ Builder version 6 and would like to add some method of invoking a batch file after a project build has been performed. There is no direct support in the IDE to do this but I have read that it is possible to modify project makefiles to perform such actions. After much digging around on the internet and experimentation i have still not managed to do get this to work.
The batch file in this case will simply invoke an exe file but may also be required to copy certain build outputs files to system directories for example.
If it makes any difference I am running BCB6 on a Windows 7 x64 laptop.
Regards
FarmerJo
You can run the bpr2mak.exe utility, passing your project *.bpr
bpr2mak.exe Project.bpr
Now you have a Project.mak file and running make.exe:
make.exe -f Project.mak
you'll build the Project.
Don't change make -f Project.mak with make Project.mak or make will try to build target Project.mak of Makefile (you can rename Project.mak in Makefile and simply call make, if you prefer).
Assembling everything in a batch file:
build.bat
#echo off
bpr2mak Project.bpr || goto :error
make -f Project.mak || goto :error
yourCommand_1.exe || goto :error
...
yourCommand_n.exe || goto :error
goto :EOF
:error
echo Failed - error #%errorlevel%.
pause
exit /b %errorlevel%
Of course you can add your additional commands under the appropriate target of the Makefile, but this way you'll have to manually edit the file after every execution of bpr2mak.
Crossbridge allows you to compile C/C++ programs to target the flash runtime. It comes with its own modified gcc within cygwin. Since SDL only provides developmental zips for VC or mingw, I'm trying to compile SDL within this cygwin environment. However Crossbridge's gcc is version 4.2.1 and according to google searches SDL cannot be compiled with gcc versions higher than 3 inside cygwin. When I run ./configure, it fails with:
*** Your compiler (/cygdrive/c/Users/Tom/Desktop/Crossbridge_1.0.1/sdk/usr/bin/g
cc.exe -jvmopt=-Xmx1G) does not produce Win32 executables!
When I just type gcc alone, I get:
bash: /usr/bin/gcc: cannot execute binary file
Does it make a difference if I compile SDL using one compiler (i.e., a lower version of gcc) and attempt to use it with the Crossbridge compiler?
Is there a workaround for this?
I checked the Crossbridge_1.0.1.zip, cc and gcc maybe are broken link (only 56 bytes?) but the gcc-4 seem to be good.
edit
type gcc-4 as you typed gcc from the bash and you'll see the usual expected no input files gcc's error message, try gcc-4 -v
the message Your compiler does not produce Win32 executables is given by the fact that whatever you've executed (or has been executed automatically) is using /cygdrive/c/Users/Tom/Desktop/Crossbridge_1.0.1/sdk/usr/bin/gcc.exe as your compiler, but as you already checked it doesn't work, and if you check it with ls -l /usr/bin/gcc.exe you'll see that this is only 56 bytes size, this can't be the real compiler, I guess it probably was a symbolic link to the real compiler, which for some reason isn't working as expected (on linux executing a symlink is as executing the real binary).
I'm not an expert of cygwin, but I guess at some level symlink are supported, reading this FAQ make me wonder if some attribute hasn't lost packaging/unpackaging the zip, so that the symlink aren't recognized.
Try to recreate it (it worked for me):
cd /usr/bin # change directory
rm gcc.exe # remove the broken link
ln -s gcc-4.exe gcc.exe # re-create the symlink
run gcc again, should return the no input files error as expected.
But this isn't the solution, because probably in the unzipped files there are many broken symlink.
I can't believe Adobe is distributing a broken SDK, so perhaps there's some instruction somewhere about how to properly unzip the SDK preserving the symlinks (maybe unzip have a preserve attribute option? I don't know much about zip sorry.
edit
execute the run.bat (the bash) and cd to the main directory where you unzipped the SDK (mine is /cygdrive/c/crossbrige)
cd /cygdrive/c/crossbrige
for f in $(find ./ -type f -print0 | xargs -0 grep '!<symlink>' -l); do attrib +S $f; done
this should hopefully fix all the broken symlink, the only side-effect is that any file containing !<symlink> will get set the attribute DOS SYSTEM, but cygwin check both this magic string at offset 0 and the S attribute to consider a file as a symlink, so hopefully will not break anything.
I used Alex find/ attribute loop to fix all broken links in my cygwin install. I have no idea why they appeared.
The first attempt failed with messages like:
Invalid switch - /usr/lib/terminfo
for each file attrib worked on.
Turned out that for my cygwin/Windows combo I had to cd into the directory and execute attrib from there. So the loop content was:
do cd $(dirname $f); attrib +S $(basename $f); done