Compilation terminated while compiling in visual studio code - c

#include <stdio.h>
int main()
{
int a = 10, b = 15, c;
c = a + b;
printf("%d", c);
return 0;
}
Whenever I tried to compile it produce error
gcc.exe: error: instruction: No such file or directory
gcc.exe: error: Arthematic: No such file or directory
gcc.exe: error: declearation: No such file or directory
gcc.exe: fatal error: no input files
compilation terminated.
Error code image

Your shell command is malformed. You used
gcc instruction Arthematic declearation.c -o instruction Arthematic declearation
when you should have used
gcc "instruction Arthematic declearation.c" -o "instruction Arthematic declearation"

Try to avoid using spaces in your file or directory name. If any of it contains spaces, than you should put it between "" marks.

Related

how to solve this problem compiler error that linker command failed in VSCODE

I wrote some C code on VSCODE like that.
The code is divided into three files: the header, the function, and main in same project folder.
But when I started compile, files are can't compile and error. like terminal text.
Maybe I think this error is linking error..
How to solve this problem..?
[source code]
mysqrt.c
#include "mysqrt.h"
#include <stdio.h>
#include <math.h>
double mysqrt(double a, double b){
double result = sqrt(pow(a,2)+pow(b,2));
return result;
}
mysqrt.h
#include <stdio.h>
double mysqrt(double a, double b);
mysqrtTest.c
#include <stdio.h>
#include <math.h>
#include "mysqrt.h"
void main(void){
double sum = mysqrt(3,4);
printf("%.2f\n",sum);
}
[terminal text]
/Users/kim_donggyun/Desktop/My File/MyFile/VSCodeWorkFolder/2019_2_finalExam/mysqrtTest.c:5:1: warning:
return type of 'main' is not 'int' [-Wmain-return-type]
void main(void){
^
/Users/kim_donggyun/Desktop/My File/MyFile/VSCodeWorkFolder/2019_2_finalExam/mysqrtTest.c:5:1: note: change
return type to 'int'
void main(void){
^~~~
int
1 warning generated.
Undefined symbols for architecture x86_64:
"_mysqrt", referenced from:
_main in mysqrtTest-45c3c1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[OS]: macOS Mojave 10.14.6
to resolve your linking issue you need to compile all your c file, as dependencies are not automatically resolved ( header files could be name separately from code file so .h files and .c files are independant ).
# assuming that gcc is your compiler
gcc -Wall -Wextra -Werror -pedantic -o mysqrtTest mysqrtTest.c mysqrt.c -lm
Although I would recommend you to learn about separate compilation, and using a build system, like make
Example of Makefile
mysqrtTest: mysqrtTest.o mysqrt.o
${CC} -o $# $^ -lm
then use make to build your binary

MinGW compilation says header files are missing, which package maybe missing?

This is the first gcc error on compilation, copying features.h from the web into the include folder for MinGW helped :
$ gcc -g hello_world.c
In file included from c:\mingw\include\stdio.h:55,
from hello_world.c:1:
c:\mingw\include\_mingw.h:174:10: fatal error: features.h: No such file or directory
#include <features.h>
^~~~~~~~~~~~
compilation terminated.
This is the new error :
$ gcc -g hello_world.c
In file included from c:\mingw\include\_mingw.h:174,
from c:\mingw\include\stdio.h:55,
from hello_world.c:1:
c:\mingw\include\features.h:406:10: fatal error: stdc-predef.h: No such file or directory
#include <stdc-predef.h>
^~~~~~~~~~~~~~~
compilation terminated.
The hello-world file :
#include <stdio.h> int main(int argc, const char *argv[]) {
/* I am C developer */
printf("Hello, Poftut! \n");
return ; }
C:\MinGW\bin\ is in PATH.Pretty sure I have missed some package installation.

Compiler can't find installed library headers

Writing my first application in C and it can't seem to find the header file (which I installed following the instructions in the readme):
#include <stdio.h>
#include <stdlib.h>
#include <ftdi.h>
int main (int argc, char *argv[])
{
int ret;
struct ftdi_context = *ftdi;
struct ftdi_version_info version;
if ((ftdi = ftdi_new()) == 0)
{
fprintf(stderr, "ftdi_new failed\n");
}
else {
fprintf(stderr, "Success\n");
}
return 0;
}
But it finds it here:
ollieb#ursus ~/Documents/BitBang $ locate ftdi.h
/home/ollieb/.local/share/Trash/files/libftdi/libftdi/ftdipp/ftdi.hpp
/home/ollieb/.local/share/Trash/files/libftdi/libftdi/src/ftdi.h
/home/ollieb/Applications/libftdi1-1.3/build/doc/html/group__libftdi.html
/home/ollieb/Applications/libftdi1-1.3/build/doc/man/man3/ftdi.h.3
/home/ollieb/Applications/libftdi1-1.3/build/doc/man/man3/ftdi.hpp.3
/home/ollieb/Applications/libftdi1-1.3/ftdipp/ftdi.hpp
/home/ollieb/Applications/libftdi1-1.3/src/ftdi.h
/usr/include/libftdi1/ftdi.h
/usr/include/libftdi1/ftdi.hpp
This is what happens when I try to compile, it says the file cannot be found (when I run examples in the code library folder they run fine):
ollieb#ursus ~/Documents/BitBang $ make
make bitbang
make[1]: Entering directory '/home/ollieb/Documents/BitBang'
cc -Wall -g bitbang.c -o bitbang
bitbang.c:3:18: fatal error: ftdi.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'bitbang' failed
make[1]: *** [bitbang] Error 1
make[1]: Leaving directory '/home/ollieb/Documents/BitBang'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
By default, compiler searches for the header files in the default INCLUDE path, not the whole filesystem.
If you have your headers in a custom path, you need to inform the compiler about that. For example, with gcc and clang, you can use the -I switch to let the compiler know the path where the header files are present.
From gcc online manual,
-Idir
Add the directory dir to the head of the list of directories to be searched for header files. [...]

C makefile undefined-reference error

I am having slight problems with using makefile in C. Ive been following a tutorial in a textbook, but it doesnt seem to want to work. I have three files, message_hider.c, encrypt.h and encrypt.c. When I create a makefile for these files it returns an error, but when I run each command individually it works just fine. Here are my files.
encrypt.c
#include "encrypt.h"
void encrypt(char *message) {
char c;
while (*message) {
*message = *message ^ 31;
message++;
}
}
message_hider.c
#include <stdio.h>
#include "encrypt.h"
int main() {
char msg[80];
while (fgets(msg, 80, stdin)) {
encrypt(msg);
printf("%s", msg);
}
}
encrypt.h
void encrypt(char *message);
Makefile
message_hider: message_hider.o encrypt.o
gcc message_hider.o encrypt.o -o message_hider
message_hider.o: message_hider.c encrypt.h
gcc -c message_hider.c
encrypt.o: encrypt.c encrypt.h
gcc -c encrypt.c
Error message
$ make message_hider
cc message_hider.o -o message_hider
message_hider.o:message_hider.c:(.text+0x17): undefined reference to `encrypt'
message_hider.o:message_hider.c:(.text+0x17): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `encrypt'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: message_hider.o: bad reloc address 0x0 in section `.pdata'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'message_hider' failed
make: *** [message_hider] Error 1
$ make message_hider
cc message_hider.o -o message_hider
That is not the rule you've specified in your makefile. First off, it appears to be using cc rather than gcc. Second, there's no mention of encrypt.o in there which is why your link is failing.
Try to explicitly use the makefile, such as with:
make -f Makefile message_hider
It may be that it's picking up a different makefile, one that either has different rules or one that simply relies on the default rules like .c.o.
And, based on your update that:
make -f Makefile message_hider
gives you:
$ make -f Makefile message_hider
make: Makefile: No such file or directory
make: *** No rule to make target 'Makefile'. Stop.
that's the error you get when Makefile does not actually exist.
So you need to check that it's in the current directory, and named exactly as you expect.
That would explain the use of default rules as mentioned earlier, since your makefile isn't actually being picked up.
Another thing to check, though it's probably moot now that we've seen the error above, is that you're actually running the correct make program. Use which make to find out where it is (should be /usr/bin/make on CygWin) and make --version to check the version.

makefile error when using string.h

I realize this has probably been answered but I just cannot find it. When using "make" to compile the following file:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
// get line of text
string s = GetString();
// print string, one character per line
for (int i = 0; i < strlen(s); i++)
{
char c = s[i];
printf("%c\n", c);
}
return 0;
}
I get the following message:
$ make example
cc example.c -o example
Undefined symbols for architecture x86_64:
"_GetString", referenced from:
_main in example-iPNXBe.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [example] Error 1
Judging from the cs50 page you probably need something like -lcs50 at the end of the cc command.
Or you can just use the cs50.o object file and link with it.
cc example.c cs50.o -o example

Resources