R
R
Ro Gry2021-09-17 14:20:16
C++ / C#
Ro Gry, 2021-09-17 14:20:16

Hello, world does not compile to C on MacBook (VS Code). What to do?

At the university, we were asked to write a program in the C language. Well, I decided first, in order to understand the language itself at least a little, to write a simple Hello, world, but nothing has been working for the second day. Let's start over:

I downloaded VS Code on a MacBook. Development environment - yes.
Next, I created a folder that I called HW Proj and through VS Code I opened a file in it that I called hello.c
By the way, I downloaded the C / C ++ extension that VS Code offered me, and also downloaded Xcode and the extension to it , which I downloaded when I first opened Visual Studio 2019 (I also downloaded it and he offered me this extension, I downloaded it)
Then I opened this folder (Open Folder) in VS Code and opened this file in it. Wrote this code:

#include <stdio.h>
int main ()
{
    printf("Hello, world!\n");
    return 0;   
}


In addition, before writing the program, I wrote clang --version in the terminal (I also tried it in the built-in from macOS and from VS Code) (as it was written in the guide)
After I wrote the code, I checked through cd ~ (in the terminal) to make sure whether I'm working in that directory. Spoiler: never succeeded, regardless of the terminal. Nothing stupid happened to me. It looked like this:
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
[email protected] HW Proj % cd ~


Well, I closed my eyes to this, because my brain was already boiling and I just typed make hello in the terminal.
I should have highlighted "cc hello.c -o hello", but instead it gave me an error
make***: No rule to make target 'hello'. Stop.

. There was also a moment when there was another error.
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.

Press the 'return' key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'

Xcode and Apple SDKs Agreement


I downloaded the Xcode application and there I gave permission for what they asked me (I also did it in the terminal, I even entered the password), but everything is even.

Here's what I ended up with:
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel] 
You can view the license agreements in Xcode's About Box, or at /Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf

[email protected] ~ % agree
zsh: command not found: agree
[email protected] ~ % make hello
make: *** No rule to make target `hello'.  Stop.
[email protected] ~ %


And here my hands have dropped. I am completely desperate and don't know what to do. Even on Hello, world I am not capable of C, apparently. Also, I don’t understand how to set in the terminal so that I work in the Desktop / Desired folder (although I wrote the whole path), instead I always work for some reason in InstalledDir: /Library/Developer/CommandLineTools/usr/bin.

UPD: I deleted the terminal and registered it again (taking into account what was advised in the comments). Already better (as it seems to me), but there is another mistake.
The code itself:
#include <stdio.h>

int main ()
{
    printf("Hello, world!\n");

    return 0;   
}


Terminal:
[email protected] HW Proj % cd ~/Desktop/HW\ Proj
[email protected] HW Proj % make hello
cc     hello.c   -o hello
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: *** [hello] Error 1
[email protected] HW Proj %

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question