visual code error: how do i fix this problem - c

I'm super new to coding I have downloaded Visual Studio and as I'm writing my first program I get this error
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)
I don't understand what to do. I have read in come post to see if I have a compiler and I believe I do
Apple clang version 13.0.0 (clang-1300.0.27.3)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
this was my code
#include <stdio.h>`int main() {printf("helloh world");return 0; }

You have a
`
in your code that's not needed and you lack white spaces between your include directive and your function declaration. Try it this way:
#include <stdio.h>
int main() {
printf("helloh world");
return 0;
}

Related

How to link libraries in Visual Studio Code

I have a school project (a mp3 music player) using C and FMOD.
I have a Mac M1 and try to use Visual Studio Code (im bad with C).
I type these lines
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include"api/core/inc/fmod.h"
int main(void){
printf("hello");
FMOD_SYSTEM* pSystem;
FMOD_System_Create (&pSystem, 0);
}
And I have this error :
Undefined symbols for architecture arm64:
"_FMOD_System_Create", referenced from:
_main in main-b18886.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
But I think Visual Studio Code can't link libraries with fmod.h, I tried the External Libraries add-on for VSC but it's not working, do you have any idea how to figures this out ?

Error on M1 Mac through GCC Compile in vim

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.

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");
}

C Problem with Compiler?

I just started learning C, and wrote my hello world program:
#include <stdio.h>
main()
{
printf("Hello World");
return 0;
}
When I run the code, I get a really long error:
Apple Mach-O Linker (id) Error
Ld /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug/CProj normal x86_64
cd /Users/Solomon/Desktop/C/CProj
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug -F/Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug -filelist /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Intermediates/CProj.build/Debug/CProj.build/Objects-normal/x86_64/CProj.LinkFileList -mmacosx-version-min=10.7 -o /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug/CProj
ld: duplicate symbol _main in /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Intermediates/CProj.build/Debug/CProj.build/Objects-normal/x86_64/helloworld.o and /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Intermediates/CProj.build/Debug/CProj.build/Objects-normal/x86_64/main.o for architecture x86_64
Command /Developer/usr/bin/clang failed with exit code 1
I am running xCode
Should I reinstall DevTools?
have you tried
int main() or even int main(int argc, char**argv) ?
The error message indicates that the symbol _main (which refers to the main() function) is defined twice, once in helloworld.o and once in main.o.
It's likely that you have two source files, helloworld.c and main.c, in the same project, and that both define a function named main.
You can only have one main function in a program. Removing one of those two source files (and the associated object file) from your Xcode project should fix the problem. (I haven't used Xcode myself; perhaps someone else can tell you how to do that, if it's not obvious.)
(And the correct definition is int main(void), not the old-style main(), but I don't think that's related to the symptom you're seeing.)
There are a couple of stackoverflow questions that could be closely related to yours:
Xcode duplicate symbol _main
Xcode, Duplicate symbol _main

Resources