exec: “gcc”: executable file not found in %PATH% when trying go build - go

I am running go on a relatively restricted system under Windows 10.
In my go program, there is some CGO code so I must have a GCC compiler to use it.
For some reason, here, it is impossible to install typical systems such as Cygwin or MSYS, which would make the task easier.
Nonetheless, I managed to install the Ubuntu subsystem.
This is great, it means that after the following command:
doskey gcc=Ubuntu run gcc
when I try to execute gcc on Windows I obtain:
C:\PathToFolder\>gcc
gcc: fatal error: no input files
compilation terminated.
However, when I try to then, compile my Go code, I have:
C:\PathToFolder\>go run Main.go
# _/C_/PathToFolder/Package/File
exec: "gcc": executable file not found in %PATH%
Is there any way to force Windows to use my own gcc command through the Ubuntu subsystem?
Thanks in advance,

Related

How to Compile Ncurses Program for Native Windows Use

I'm trying to compile a C program using Ncurses on Windows. I compiled it successfully using GCC and it works perfectly if I run it in Cygwin or MSYS2. However, if I try to run it in the Windows Command Prompt, I get this error:
Error opening terminal: xterm-256color.
Is it possible to compile it to run using the native Windows console? This is how I've been compiling it:
gcc -o PROGRAMNAME main.c -lncurses
I also have the Cygwin and Msys dlls for Ncurses copied into the directory of the compiled executable.
Update
So I figured out how to get the program to run. I deleted all the DLLs from the project folder and then added "C:\msys64\usr\bin" to my PATH environment variable. However, I would still like to know if there's a way to get this to work if I were to distribute it, since it's still relying on my installation of MSYS2.
Update 2
Gave up and just used pdcurses and it works fine.
Update 3
Nevermind, found a solution! See below.
I figured out a solution. I'll post it here in case anyone else has this same issue. Thanks to Thomas Dickey for your help!
Install the mingw-w64 toolchain and any other packages you need to compile your project (this is mostly where I messed up)
Make sure to include the /mingw64/include/ncurses directory when compiling, or else gcc won't be able to find curses.h
Include /mingw64/bin as a static directory or copy over the necessary dlls to the same folder as the directory
I ended up with this to compile:
gcc -I/mingw64/include/ncurses -o PROGRAMNAME main.c -lncurses -L/mingw64/bin -static

How do I compile the source code for ADB (Android Debug Bridge)?

I'm trying to run a memory error detector (like Valgrind's Memcheck or Drmemory) on the ADB software. However, I'm having trouble figuring it how to build/compile the source code. I'm using linux (ubuntu).
https://github.com/aosp-mirror/platform_system_core/tree/master/adb
Do I need a makefile? Or is there something wrong with my understanding on how to go about doing this? Maybe there's a way that I can use Memcheck/Dr. Memory on the actual program when it's run in Android Studio? I don't believe there are any instructions, or a makefile in the source code.
I've tried compiling the main.cpp file in the client folder with g++, but it says it doesn't have access to the sysdep.h file.
Compiled using:
$ cd client
$ g++ -std=c++11 main.cpp -o main
Error message:
fatal error: sysdep.h: No such file or directory
Take a look at this documentation for the AOSP ADB tool:
https://source.android.com/setup/build/adb#building_adb_build-adb
From my understanding you need to download the AOSP source code then run the following commands:
source ~/aosp/build/envsetup.sh
cd ~/aosp/system/core/adb
mm # <- That's not a typo
This command should take a while (especially on the first run) but you should get a compiled adb executable in the ~/aosp/out folder somewhere (I can't verify on this computer as it doesn't have enough ram to complete a build...)
Also to show the help menu, type:
hmm

Nim compiler fails with "Requested command not found: gcc.exe"

I tried to launch first program in nim. I downloaded Windows installer from the official site and did the installation with all possible components. But when I try to run the program I get the message:
"unhandled exception: Requested command not found: 'gcc.exe -c -w -IC:nimlib -o
c:nimworknimcacheaa.o c:nimworknimcacheaa.c'. OS error: [OSError] >
Process terminated with exit code 1"
is it possible to fix this situation?
From Nim's website:
Note: The Nim compiler requires a C compiler to compile software. On Windows we recommend that you use Mingw-w64. GCC is recommended on Linux and Clang on Mac.
Make sure to add the gcc binaries to your PATH.
download nim lag and exract the file and paste it in your directory lib

gcc fails with spawn: No such file or directory

I downloaded
Ruben’s build of
Cygwin GCC.
However upon running it seems unable to compile any files
$ touch foo.c
$ gcc foo.c
gcc: error: spawn: No such file or directory
As a workaround, I found this to work
i686-w64-mingw32-gcc foo.c
I had the same problem and solved it by installing the g++ package in addition to gcc-core
I had this same problem on Cygwin64, and the solution was PATH related..kinda.
Turns out, there are copies of gcc in /usr/bin and /bin (at least, there is in my install).
Executing /bin/gcc failed with the error above -- I'm guessing due to incorrectly assumed relative paths???
Executing /usr/bin/gcc works as expected!
In my case, the "problem" was that I had inadvertently injected "/bin" into my PATH environment variable, resulting in /bin/gcc being executed, instead of /usr/bin/gcc. Removing the "/bin" from the path solved the problem.
Still unclear why there are two gcc binaries (which appear to be identical) in different places... but maybe the Cygwin gurus can answer that; or maybe my installation is just foo-barred.
Ruben's builds are not Cygwin GCC packages, rather they are cross-compilers which run on various platforms but target native Windows using the MinGW-w64 toolchain.
In any case, you shouldn't be using them on Cygwin. If you want to compile Cygwin executables, install the gcc4 packages; if you want to cross-compile for Windows, install the mingw64-i686-gcc (for Win32) or mingw64-x86_64-gcc (for Win64) packages instead.
Gcc isn't really the compiler. It's a front end program that orchestrates the execution of any necessary compiler, assembler, and linker components. Typically these others are separately compiled programs.
So, gcc is trying (kind of) to tell you that it can't find the compiler. I guess it needs to be on your PATH or in an expected location.
If you are executing this from a Windows DOS box then it definitely needs a windows PATH setting.
I like to install Cygwin, making sure to include rxvt. At that point, you can configure a purely sh(1) path and your environment is rather more civilized.
I had the same error when I tried to extract a couple of executables from cygwin installation dirctory and copied them into another location.
strace shows me the file which was not found by spawn:
/lib/gcc/x86_64-pc-cygwin/6.4.0/cc1.exe
When I copied cc1.exe into the location relative to
<dir with sh.exe and cpp.exe>/../lib/gcc/x86_64-pc-cygwin/6.4.0/cc1.exe
it works fine.
This error occurs whenever cygwin cc can't find a required file.
For those running stuff within cygwin's bin directly from a Windows shell, a gotcha to watch out for is that Windows allow you to run programs from the command line like this:
e:cyg/bin/gcc -flags
Notice that there is no slash between e: and cyg.
So this command would successfully start cygwin gcc from the Windows shell, but halfway through the run it will error out because some component(s) of gcc will utilize the first argument of the input e:cyg/bin/gcc and unlike mingw, this is not a valid path for cygwin gcc.
This can be fixed simply by changing the command to:
e:/cyg/bin/gcc -flags
Notice the slash in between e: and cyg.
A similar gotcha is due to Windows allowing paths like e:/../folder1 as an alternative to e:/folder1. Windows does not give you an error if you are at the root folder and try to go up another folder using ...
So you could start running cygwin gcc using the command:
e:/../cyg/bin/gcc -flags
..or even:
e:/../../../../../../../../../cyg/bin/gcc -flags
However, it would fail halfway with gcc: error: spawn: No such file or directory because some component(s) of cygwin gcc would attempt to run gcc using the first argument of the command input itself, and unlike mingw, e:/../cyg/bin/gcc is not recognized as a valid path by cygwin because you are going up a folder when there's no folder to go up to.
As like above, this can be fixed by keeping the path valid:
e:/cyg/bin/gcc -flags
Make sure the source file extension is in lowercase (i.e. main.c, not main.C):
$ gcc -o main main.C
$ gcc: error: spawn: No such file or directory
$ gcc -o main main.c
$ # all good
This only refers to the case of the extension as given to the gcc, the actual source file can have the extension in whatever case you want.
Explanation: This is from my experimenting with cygwin and gcc, I don't know the actual reason for this behavior.

Can I use link.h on a cygwin install?

I have installed the latest version of Cygwin, selecting the following packages during setup:
libgcc1
gcc
gcc-core
And created a file (test.c) with only this line:
#include <link.h>
Then ran the following from my Cygwin bash:
$ gcc test.c
... but got this error:
test.c:1:18: link.h: No such file or directory
Any ideas how I can fix it?
Cygwin is based on the Win32 subsystem, which means it uses Windows' executable format (COFF) and dynamic linker, i.e. it does not have an ELF dynamic linker. Hence providing the ELF-specific <link.h> would probably make little sense.

Resources