running gcc in cygwin - gcc

I have installed Cygwin on my system. But when I try to use the gcc command it says:
bash: gcc: command not found
Can anyone provide me the solution, please?

In my installation there was no generic gcc command either, so I made a symlink for it:
cd /usr/bin
ln -s i686-pc-cygwin-gcc-3.4.4.exe gcc
Now check if it worked by doing which gcc which should give you /usr/bin/gcc and then gcc should give you gcc: no input files. Note that your version of i686-pc-cygwin-gcc-3.4.4.exe may be different. Check in /usr/bin for it.

Maybe during installation of Cygwin you have not selected gcc, gdb and make packages.
I had the same problem and it was resolved after I selected above-mentioned packages.

A couple of things:
I always install the whole Cygwin package. Earlier versions had troubles with dependencies that are fixed now, I believe, but it's still a good habit. You never know when you may need the most esoteric bit of Cygwin.
You may have to change your path. All the tools can generally be found okay if you're running inside the Cygwin bash shell but that's not necessarily the case from cmd.exe.
It's unlikely to be that last one since your error message is coming from bash itself, so I'm pretty certain that's how you're running it.
Have a look to make sure you have /usr/bin/gcc from within bash and that your path includes /usr/bin somewhere:
pax> echo $PATH
/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS
pax> which gcc
/usr/bin/gcc
If it's not there, go back and re-install everything (or the relevant development package if you don't want everything). If it is there and your path doesn't have its location, change your path, in either /etc/profile or the equivalent in your home directory.

Another related issue that wasn't mentioned here, is from the command line the compiler needs the environment path variable updated to find the location of the c++ header files. In windows you can just update the path environment using the 'advanced system properties' GUI and add the location of the c++ include files. This will update the PATH environment variable in Windows cmd & Cygwin automatically upon restarting the shell.
To update your PATH from Linux or the Cygwin shell type... PATH=$PATH:/your_path_here Example:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/c++ Also a good idea to add just the include directory as well: PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/ ...or check the proper directories for the location of your installation's include files, I recommend installing mingw for use with Cygwin, which is envoked with g++.
To install additional needed packages in Cygwin re-run the Cygwin install utility & check install from Internet to add packages from web repositories and add mingw-gcc-g++ & mingw-binutils. To compile your code: g++ hello.cpp -o hello
If using the gcc utility instead compile with the command: gcc hello.cpp -o hello -lstdc++ ... to get your executable.
As long as you have either gcc or mingw installed and the path to the c++ include files is in your path environment, the commands will work.

There is another hard to spot mistake could also cause this error,
If your Makefile uses PATH as variable, the gcc not found error could happen.
This is because it changes the system path temporarily.
I took a lot of time checking the cygwin environment setting to discover this, so I'll leave it here in case this helps anyone finding their way here.

Related

Installing gfortran in Linux as a user

I am a non-administrator user of a Linux (CentOS 6.6) server at work. I log in through a terminal program on a windows computer. My problem is that the IT does not feel comfortable upgrading GCC/gfortran for me so I want to just run it from my personal folders. They claim the latest yum (devtoolset-3 for this OS version) will downgrade some other feature they have. It's not the latest version of GCC anyway.
I have downloaded the latest GCC 5.3 binaries and prerequisites from gfortran.com and can almost get my test code to compile. Actually, when I do the following it will compile with -c but will not not link. That folder is where I put the prerequisites and also I copied stuff from the /usr/lib64 directory into there as well.
LD_LIBRARY_PATH=/users/home/me/me/gcc53mark/my_lib
export LD_LIBRARY_PATH
./gfortran test.f90
The error message is as follows:
collect2: fatal error: cannot find 'ld'
But ld does exist
-bash-4.1$ whereis ld
ld: /usr/bin/ld /usr/share/man/man1/ld.1.gz
After much effort I have answered my own question! To install GCC to my own personal Linux account as a non-administrator, I ended up having to compile GCC and not use the binaries I originally downloaded. My friend was make install which knows where everything needs to go, which I did not have with the binaries.
The key was to install to my user root directory /GCC with the following command provided with the build-it-yourself method (-prefix):
../gcc-5.3.0/configure --prefix$HOME/gcc-5.3.0 --enable-languages=c,c++,fortran --disable-multilib
For me I had to disable multilib because I guess my system only has 64 bit libraries (I think this was causing my original problem).
Before I got to that point, I had to also download the prerequisites manually since my workplace I suppose blocks the automatic prerequisite downloader as referenced in these instructions.
https://gcc.gnu.org/wiki/InstallingGCC
Prerequisites need to be taken from here, placed into the root of the directory that gets created when you unzip GCC. Then unzip them and link them as is done in the batch file you have already unzipped ./contrib/download_prerequisites.
ftp://gcc.gnu.org/pub/gcc/infrastructure/
Finally I need to run the following command, after it is all up so it looks at the new libraries. I will add this to my .profile when I am ready to fully switch to the local newer version.
LD_LIBRARY_PATH=/users/home/myself/gcc-5.3.0/lib64
export LD_LIBRARY_PATH
For now I am running gfortran with the following command but also I will add this to my .profile later.
/users/home/myself/gcc-5.3.0/bin/gfortran Test.f90
It works! Latest version of GCC running from my local Linux user non-administrator account!
Edited to add how we resolved this for the network group:
IT did not want to overwrite the original installation so we installed to some network folder /gcc-5.3.0 . Then we modified the group's .profile to add the library and binary paths to that, before the standard path.

CLion Installation: Cmake compilers not found, GDB not found

I'm switching from VS to CLion and they said I needed to install Cygwin and CMake. I then installed both of them. I tried use bundled, but CLion still gives me these errors make: not found C Compiler: not found C++ Compiler: not found GDB: not found.
I have installed CMake under the path C:\Users\Gaga\Downloads\cmake-3.4.1 but I don't see a cmake.exe, the closest thing is cmake.cxx.
Without these I'm not able to compile anything, please help
In the "Use specified" field I put C:\cygwin64\bin\cmake.exe your path may be different. Just ensure you have CMake, Make, gdb and gcc installed already in Cygwin (using the Cygwin setup.exe not via the CMake website) but I believe Clion checks if you have them installed after inputting the path.
The workaround would be to use MinGW. If you download it from the website it should come with cmake, and take care of the errors.
http://mingw.org/
When extract it and go to the installer you should check something like gcc and then from the top left corner something like 'install packages'
Be sure not to accidentally download the source, which I did, which would lead you toward this error: CLion: CMake Errors Source directory does not exist
Edit: So over a year later, I've learned a little more about Cygwin and mingw beyond what the internet says. CLion needs a "Unix-like" environment. If you use CLion on MacOS or a Linux it's already Unix based. Anything that is "POSIX" compliant will work. CygWin is a terminal emulator for windows where Unix commands like mkdir work. MinGW is something similar but not posix. Comes with GCC tho. I'm still a noob.
I had the same problem.
While installing cygwin, need to select the packages of cmake, gcc, gdb
Got the answer from the below link.
Select Packages while installing cygwin
After the installation go to the configuration page and select the cygwin directory. CLion will identify the configuration and you are done...

how to use cmake that installed in a non-standard path?

I am on Ubuntu 14.04.3 platform. While I was compiling a project it asked cmake version 3.2 which is not present in my system. I compiled the latest version of cmake from source code and installed it into /usr/local/bin directory. When I attempt to compile project again, its cmake detects the cmake in /usr/bin which is lower version. Then cmake ..
process aborts with lower version error. Is there any built-in cmake variable or environment variable for setting path of the cmake?
EDIT:
I just found a cmake variable CMAKE_COMMAND that supposedly does what I want.
But when I insert CMAKE_COMMAND = /usr/local/bin/cmake line into cmakelist.txt then I go to build directory and issue /usr/local/bin/cmake ..
I get :
Expected a command name, got unquoted argument with text
I searched for it on the net but didn't find a solution.
If you have different versions of a software or library installed you may use stow to install and switch between the two. Especially if you want to install a newer version of a software that is not available in one's Linux distribution. So in case the new version is not yet stable you can still switch to the previous one. For example while building cmake 3.2 you can specify the prefix as
./configure --prefix=/usr/local/stow/cmake-3.2/
and then
cd /usr/local/stow
sudo stow cmake-3.2
and if you want to remove the links you can use the following command
sudo stow --delete cmake-3.2
Please keep in mind stow does not delete files. It only makes and deletes links.

CMAKE_MAKE_PROGRAM not found

I have reached the end of my rope with CMake; it has so much potential, but I cannot seem to make it find the basic system tools (i.e. make) in order to function.
SYMPTOMS
CMake and the CMake GUI produce the following (after deleting the CMakeCache.txt file):
Processing top-level CMakelists.txt for project swb
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".
CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
I am focusing on finding make in this question, however, I've also had many of the same issues with CMake failing to find libraries and other utility files (linker, nm, ar, etc.). The techniques I list below seem to enable CMake to find these files when running under Linux.
SYSTEM
Windows 7 (64-bit); multiple versions of MinGW (32-bit/64-bit); Cmake 2.8.4;
NONSTANDARD install location for MinGW (c:/MinGW-32 ).
THINGS I HAVE TRIED
CMakelists.txt contains SET( CMAKE_MAKE_PROGRAM c:/MinGW-32/bin/make.exe FORCE ) within the first 10 lines of the file.
Previous versions of CMakelists.txt contained:
find_program(CMAKE_MAKE_PROGRAM
NAMES make
make.exe
DOC "Find a suitable make program for building under Windows/MinGW"
HINTS c:/MinGW-32/bin )
Set CMAKE_MAKE_PROGRAM in a cmd.exe environment variable prior to running either CMake or CMake-GUI.
Use of a "toolchain" file which identifies CMAKE_MAKE_PROGRAM as well as CMAKE_C_COMPILER, etc.
ONE THING THAT HAS WORKED
CMake will successfully create build files IF I use the GUI to populate the CMAKE_MAKE_PROGRAM variable ("C:/MinGW-32/bin/make.exe").
QUESTION(S)
I can get CMake to work if I identify the name of the make program via the GUI. How does one enable CMake to find my make program without user intervention with the Windows 7 (64-bit) / MinGW combination?
I have two suggestions:
Do you have make in your %PATH% environment variable? On my system, I need to add %MINGW_DIR%\bin to %PATH%.
Do you have make installed? Depending on your mingw installation, it can be a separate package.
Last resort: Can you pass the full path to make on the commandline? cmake -D"CMAKE_MAKE_PROGRAM:PATH=C:/MinGW-32/bin/make.exe" ..\Source
In the GUI, select the "Advanced" checkbox. It should now show several entries below. Rename your mingw32-make.exe file to make.exe (you can just make a copy) and set the CMAKE_MAKE_PROGRAM filepath variable to the location of said file.
On ubuntu, i think I was missing the compiler. Fixed with:
sudo apt install build-essential
I’ve just solved the same problem. I had MinGW with GCC and G++ installed but not make. This command helped me:
mingw-get.exe install mingw32-make
After running it, clear CMake cache (delete the CMakeCache.txt file in the CMake's working directory) and run CMake again.
Previous answers suggested (re)installing or configuring CMake, they all did not help.
Previously MinGW's compilation of Make used the filename mingw32-make.exe and now it is make.exe. Most suggested ways to configure CMake to use the other file dont work.
Just copy make.exe and rename the copy mingw32-make.exe.
I have tried to install the missing packages. Installing the toolchain and restarting CLion solved all in my case:
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-extra-cmake-modules
pacman -S mingw-w64-x86_64-make
pacman -S mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-toolchain
Recently i had the same problem (Compiling OpenCV with CMake and Qt/MinGW on WIN764)
And I think I solve this including on my environment variable PATH (through Control Panel\All Control Panel Items\System\Advanced Sytem Settings) with the %MINGW_DIR%\bin and %CMAKE_DIR%/bin
Furthermore, I installed cmake2.8 on an easy directory (without blanks on it)
I had the exact same problem when I tried to compile OpenCV with Qt Creator (MinGW) to build the .a static library files.
For those that installed Qt 5.2.1 for Windows 32-bit (MinGW 4.8, OpenGL, 634 MB), this problem can be fixed if you add the following to the system's environment variable Path:
C:\Qt\Qt5.2.0\Tools\mingw48_32\bin
I had the same problem.
Installed mingw using the installer provided at http://tdm-gcc.tdragon.net/ . It adds the correct environment variables to path when installing mingw (No need to edit the path variable manually).
That did the trick for me.
Well, if it is useful, I have had several problems with cmake, including this one. They all disappeared when I fix the global variable (in my case the MinGW Codeblocks) PATH in the system. When the codeblocks install is not in default, and for some unknow reason, this global variable does not point to the right place. Check if the path of Codeblocks or MinGW are correct:
Right click on "My Computer"> Properties> Advanced Properties or Advanced> Environment Variables> to Change the PATH variable
It worked for me;)
I had the same problem and specified CMAKE_MAKE_PROGRAM in a toolchain file, cmake didn't find it. Then I tried adding -D CMAKE_MAKE_PROGRAM=... in the command-line, then it worked. Then I tried changing the generator from "MinGW Makefiles" to "Unix Makefiles" and removed the -D CMAKE_MAKE_PROGRAM from the command-line, and then it worked also!
So for some reason when the generator is set to "MinGW Makefiles" then the CMAKE_MAKE_PROGRAM setting in the toolchain file is not effective, but for the "Unix Makefiles" generator it is.
It seems everybody has different solution. I solved my problem like:
When I install 64bit mingw it installed itself to : "C:\Program Files\mingw-w64\x86_64-5.1.0-posix-seh-rt_v4-rev0\mingw64\bin"
Eventhough mingw-make.exe was under the path above, one invalid charecter or long path name confused CMake. I try to add path to environment path, try to give CMAKE as paramater it didn't work for me .
Finally I moved complex path of mingw-w64 to "C:/mingw64", than set the environment path, restarted CMake. Problem solved for me .
I had the same problem which is solved using the following:
Try to rename all the folders to not to be more than 8 characters and without spaces.
It also happens when I just want to compile opencv2.3.2 with mingw32 (in tdm-gcc suites). Often when I install the tdm-gcc, I would like to rename the mingw32-make.exe to make.exe. And I thinks this could be the question. If cmake is asked to generated a MinGW Makefiles, It would try to find ming32-make.exe instead of make.exe. So I copy the make.exe to mingw32-make.exe and reconfigure in Cmake-gui. Finally it works! So I'd like to advise to find whether
you have mingw32-make.exe or not to solve this question.
I tried to use CMake to build GammaRay for Qt on Windows with mingw. So, I had the Qt installed. And I had the same problem as other users here.
The approach that worked for me is launching cmake-gui from Qt build prompt (a shortcut created by Qt installer in "Start Menu\All programs\Qt{QT_VERSION}" folder).
I had to add the follow lines to my windows path to fix this. CMAKE should set the correct paths on install otherwise as long as you check the box. This is likely to be a different solution depending on the myriad of versions that are possible to install.
C:\msys64\mingw32\bin
C:\msys64\mingw64\bin

How to compile a yacc (.y) file using Bison in Windows environment?

I've read http://dinosaur.compilertools.net/bison/bison_5.html#SEC25. But following those instruction i can not compile my yacc file using bison
How do i compile my file in windows 7 ... ?
Please help me to do this.
There is a common reason why bison will not operate properly on Windows and is mentioned in the install instructions but often overlooked. It is important that the name of the location of the directory that bison (and flex) is installed in (the path) does not contain a space. in particular this means that it cannot be placed under C:\Program Files\. The problem is that this directory might be suggest as the default install location. It is sometimes necessary to manually change the default to somethings else (like C:\GnuWin\ or similar). It is also usually necessary to manually add the appropriate directory to the PATH environment variable. Once this has been done there should be no problems in running bison and flex from the command prompt. It would normally be used in the following way:
flex lang.l
bison lang.y
gcc -o lang.exe lang.tab.c -lfl
It is not necessary to install MinGW, Cygwin or use Powershell or a VM or use linux as indicated by #DavidHefferman
If you still can't get it right, I even have an instructional video!
Using those Unix commands in Windows PowerShell might work, but I'm not sure and I'm currently not on Windows, so I can't check it.
If that fails you could try installing Cygwin (a basic Linux environment in Windows). You'd have to select the bison package during installation. It comes with its own shell that you can use.
Actually my personal favorite when programming under Windows is setting up a virtual machine with VirtualBox. That way you could use a real Linux environment without actually leaving Windows.
Good luck!

Resources