C program files compiling with VIM on windows10 - c

Is there anything that I need to configure in order that VIM on my Win10 machine compiles my C files?
As of this moment, VIM throws me into the DOS prompt with the following:
[No write since last change]
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file a.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
shell returned 1
Press ENTER or type command to continue

Add the following to your _vimrc file
set makeprg=gcc\ -o\ %:r\ %\ -Wall
Also, add the bin directory of your gcc compiler to the path.

Related

Can't configure C in Visual Studio Code, Windows

Hi I am getting the following error when I try to run a simple Hello World code in VS code
[Running] cd "c:\Users\nokni\FirstProgram\" && gcc HelloWorld.c -o HelloWorld && "c:\Users\nokni\FirstProgram\"HelloWorld
c:/users/nokni/new folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find c:/users/nokni/new: No such file or directory
c:/users/nokni/new folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o: No such file or directory
collect2.exe: error: ld returned 1 exit status
Any idea why?
The error messages are clearly showing that they are expecting two locations:
c:/users/nokni/new
and
folder/library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o
This should be very indicative that the folder "new folder" is not correctly recognised in the path. The directory name should have been properly escaped or embedded in quotes:
"c:\users\nokni\new folder\library\mingw-w64\..etc.."
or
c:\users\nokni\"new folder"\library\mingw-w64\..etc..

Is there a way to find the root of this error?

Im trying to compile some files with this given gcc command on a server cluster through Mac terminal:
gcc -o driver -std=c11 -Wall -W -ggdb3 driver.c ASMParser.c ParseResult.c Generate.o Grader.o
And get this error:
/usr/bin/ld:Grader.o: file format not recognized; treating as linker script
/usr/bin/ld:Grader.o:1: syntax error
collect2: error: ld returned 1 exit status
but its not very helpful considering Grader.o is a file I didn't even modify, it was provided by the teacher.
Any help on how to fix this? I have compiled it successfully using that gcc command before but after I added a few more implementation details in ASMParser.c it started giving me this error. Im expecting it to create a file called "driver" that I can run like this:
./driver "test file" "results.txt"

Error when compiling with MinGW

I am trying to compile a hello world program using MinGW on Windows 10. I am compiling from the command prompt with just:
gcc hlw.c
However, I get the following error:
d:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
Obviously, my program does not use threads; it should just print one line to the output. What is going wrong?

Eclipse GCC C Cross Compiling for OpenWrt not working

I am a beginner in both linux and openwrt. Sorry if this is a stupid question.
I am following this tutorial : https://downloads.openwrt.org/docs/eclipse.pdf
Chip : MT7620
Toolchain Prefix : mipsel-openwrt-linux-
Toolchain Path : /ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14
Code:
#include <stdio.h>
void main()
{
printf("Hello World");
}
Error:
**** Build of configuration Debug for project hello ****
make all
Building target: hello
Invoking: Cross GCC Linker
mipsel-openwrt-linux-gcc -L/ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/lib -o"hello" ./main.o
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
/ligo/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/lib/gcc/mipsel-openwrt-linux-musl/5.3.0/../../../../mipsel-openwrt-linux-musl/lib/crt1.o: In function `_start_c':
/ligo/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/musl-1.1.14/crt/crt1.c:17: undefined reference to `main'
/ligo/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-5.3.0_musl-1.1.14/musl-1.1.14/crt/crt1.c:17: undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [hello] Error 1
add the following 2 lines at the end of bashrc
export PATH=$PATH:~/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin
export STAGING_DIR=~/openwrt/staging_dir
source ~/.bashrc
To open/create the bashrc you can execute
sudo gedit ~/.bashrc
Well I feel stupid when I have to figure this problem which happens too often.
I get the above error when I forget to save the file that contains main() it gives this error since the file is empty until you save it.
These instructions tell how to automatically save all the modified files when you kick off a build Save before build Keep this set and you won't see this again.
If you don't have the path to the toolchain set in eclipse, it never even finds a compiler, assembler or linker so it can not produce the error given. The warnings about STAGING_DIR are harmless in this case.

GCC compiler errors with “No such file or directory”

My Ubuntu version is 14.04 LTS. I have a C program copied on the desktop by the name sendRawEth.c. When I write:
gcc sendRawEth.c -o sendRawEth
The compiler complains:
gcc: error: sendRawEth.c: No such file or directory
gcc: fatal error: no input files
I have no idea how to solve this error.
please do the following.
On terminal check the present directory by 'pwd' command and then check the directory in which your programme is there and see if they are same or not. And while writing gcc yourfile it's case sensitive. Hope this helps
There are 2 reasons for such errors.
You said you copied your C programs in your desktop folder.
This means you may have only copied sendRawEth.c. file format not the executable file.
You should ensure you copy the .exe files as well.
You need to change the directory to the same folder that you copied your programs into.
First, check your current folder by typing pwd.
Then change it to your required folder with:
cd /outerfolder/your program folder
Then compile it with:
gcc -o programname programname.c
And finally execute it with:
./programname

Resources