How to compile a c file with multiple words name - c

I'm very very new to programming and mostly self taught (using command prompt). I tried to compile a c file that has multiple words as its filename and it showed error for all the words.
Example:
C:\Users\User\Desktop\Programming\toCompile>gcc -o Even or odd.exe
Even or Odd determinator.c
gcc: error: or: No such file or directory
gcc: error: odd.exe: No such file or directory
gcc: error: Even: No such file or directory
gcc: error: or: No such file or directory
gcc: error: Odd: No such file or directory
gcc: error: determinator.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Do I have to rename the c files to one word names or is there another way?

Surround the file names in ' or ".
gcc -o 'Even or odd.exe' 'Even or Odd determinator.c'
But in the future, I'd avoid spaces in file names. Some build systems (make) can't work with spaces.

Related

C program is not running on Visual Studio Code

[Image][1]I am using an Ubuntu machine. I want to run C program on Visual Studio code. I have installed C/C++ extension and CODE RUNNER extension to my VS Code. But when I am going to run a simple program, it is showing me errors. What should I do now ?
tony#Jarvis:~/Desktop/c program$ cd "/home/tony/Desktop/c program/" &&
gcc Hello World.c -o Hello World && "/home/tony/Desktop/c program/"Hello World
gcc: error: Hello: No such file or directory
gcc: error: World.c: No such file or directory
gcc: error: World: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Your file name should not contain any spaces. I see Hello World.c. This will not work. Try changing it to HelloWorld.c
Your file name has spaces, Hello World.c. Having spaces while using a Command Line too like gcc is not good. Stay away from spaces as much as you can. In this case gcc thinks that Hello and World.c are separate files.

including linux headers in c program throwing errors for not finding headers

I am compiling small program with couple of header files and a source file. the code is here
https://elixir.bootlin.com/linux/v5.10/source/tools/testing/selftests/net/psock_tpacket.c
https://elixir.bootlin.com/linux/v5.10/source/tools/testing/selftests/kselftest.h
https://elixir.bootlin.com/linux/v5.10/source/tools/testing/selftests/net/psock_lib.h
It needs kernel header files so I tried something like this
# gcc -I//usr/src/linux-headers-5.10.0-kali7-common/include psock_lib.h kselftest.h psock_tpacket.c -o t.o -I.
But AM getting compilation errors like this
psock_lib.h:50:24: error: array type has incomplete element type ‘struct sock_filter’
1 ⨯
there are number of these errors.
above error simply simply thrown because struct sock_filter not found which exists in linux headers
in my usr/src/ directory
I have linux-headers-5.10.0-kali7-common & linux-headers-5.10.0-kali7-amd64
in gcc command I am specifying -I/usr/src/linux-headers-5.10.0-kali7-common/include is this correct?
both linux-headers-5.10.0-kali7-common/include and linux-headers-5.10.0-kali7-amd64/include have makefile

How do I have a makefile correctly recognize includes in multiple directories

I have been struggling with having my make file properly compile all of my source files due to an include error at compile time. I have looked at some questions online but the solutions do not seem to fix mine.
I can get this program to compile if I have all of the source files in the same directory but once I tried splitting up the files into separate directories it no longer worked.
Here is is the error:
~/Documents/GitHub/testing$ make build
gcc -I/. -Wall main.c inplementation/inplementation.c -o program.exe
In file included from main.c:3:
./inplementation/inplementation.h:4:10: fatal error: 'module/module.h' file not found
\#include "module/module.h"
1 error generated.
In file included from inplementation/inplementation.c:1:
inplementation/inplementation.h:4:10: fatal error: 'module/module.h' file not found
\#include "module/module.h"
1 error generated.
make: *** [build] Error 1
Here is a screenshot of my file directory:
Here is a screenshot of my include paths of this project:
Here is a screenshot of my make file (specifically build):
You use #include "module/module.h" while the include flag is -I/$(TESTING_DIR)/module.
First of all I think you probably meant -I$(TESTING_DIR)/module, otherwise you are adding an extra slash before the path stored in TESTING_DIR.
But the main problem is that module/module.h doesn't exist under that module folder. So you need to do one of these combinations:
-I$(TESTING_DIR)/module and #include "module.h"
-I$(TESTING_DIR) and #include "module/module.h"

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

CROSS COMPILE:arm-eabi-gcc -static -o hello hello.c

while cross compiling (application)"arm-eabi-gcc -static -o hello hello.c" following error occurring
hello.c:1:18: error: stdio.h: No such file or directory
hello.c:2:19: error: stdlib.h: No such file or directory
hello.c:3:19: error: string.h: No such file or directory
hello.c:4:19: error: fcntl.h: No such file or directory
hello.c:5:20: error: unistd.h: No such file or directory
hello.c:6:23: error: sys/types.h: No such file or directory
hello.c:7:22: error: sys/stat.h: No such file or directory
hello.c:8:23: error: sys/ioctl.h: No such file or directory
`
I am able to cross compile kernel modules.
if you try to cross-compile user program in linux machine, you shoud use not arm-eabi-gcc but arm-linux-gnueabi-gcc.
you have a broken crosscompiler. Get a better toolchain, you have a lot of options:
OpenEmbedded
Yocto
Buildroot
Scratchbox

Resources