Error on M1 Mac through GCC Compile in vim - c

I try to compile C files in vim environment but It occurs on error that
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My command is
gcc [filename.c] -o [filename]
and my file is
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
It is just simple code for checking compile.
But it didn't work.
So I wondering that what is the critical problem that occurs problem.
My command or M1 mac?
Of course I install gcc through 'HOMEBREW'.
Thank you.

Related

CS50 get_string error linker command failed with exit code 1

I am doing Harvard CS50 c course. When I type make file in the terminal it throws me this error:
Undefined symbols for architecture arm64:
"_get_string", referenced from:
_main in hello-c42e93.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello] Error 1
hello.c:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
string answer = get_string("What's your name? ");
printf("hello, answer\n");
}
I installed cs50.h library through this steps https://github.com/cs50/libcs50
I am using macOS Ventura 13.1
edit: here is the link of a cs50 library https://github.com/cs50/libcs50/tree/main/src
As #LHLaurini mentioned above you need to link with the cs50 library which contains the definition of the function get_string():
clang hello.c -o hello -lcs50
You didn't supply the Makefile but usually you can set this variable which is used in a implicit link rule:
LDLIBS := -lcs50

Mac mini m1 + VS Code + C Programming = Not Working

I am self learning to code in C using Mac mini M1 and VS Code. I get the below error:
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please note:
Installed the VS Code Insiders for ARM apple version!
Clang is installed!
Xcode command line tools installed!
C/C++ 1.4.0-insiders2 extension is installed in VS Code!
Code Runner 0.11.4 is installed in VS Code!
Code:
#include <stdio.h>
int main()
{
printf("test");
return 0;
}
Compiled using:
gcc -Wall -Wextra -Werror -o test test.c
Okay! It's because you forget to save your program before executing i.e you should compile and run. Instead of just running it! #Keeplearning!

linker command failed while trying to compile .c file with g++

Just posted a simple c code and gotten this error message. can anyone explain where the problem could be?
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mac#MACs-MacBook-Pro-2 C % cd "/Users/mac/C/" && g++ tes.c++ -o tes && "/Users/mac/C/"tes
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
you have to compile with gcc and not g++, g++ is to compile .cpp or .cc files
gcc tes.c++ -o tes

Eclipse C compiler throwing errors

I was trying to compile helloworld.c in Eclipse Oxygen.1 on Mac 10.12.6
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("Hello World!");
return 0;
}
and it throws such an error:
20:41:02 **** Incremental Build of configuration Debug for project HelloWorld ****
make all
Building target: HelloWorld
Invoking: Cross GCC Linker
gcc -o "HelloWorld" ./helloworld.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [HelloWorld] Error 1
20:41:03 Build Finished (took 938ms)
I am quite sure that the problem isn't the code itself, but what?

Symbol(s) not found for architecture x86_64 while compiling a C file

I tried to run a c file using Mac Terminal. So I put the following command in the Terminal.
gcc main.c
And the following message was shown.
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Prior to this, I also tried to build a C project in Eclipse, but this also showed an error. It says there is one error which is symbol(s) not found for architecture x86_64.
your program is missing the entry point (main function), you have to add this function to your code source.
int main(void){
printf("Hello World");
}

Resources