Problem with programming "C" on MacBook Air (Intel Prozessor) "Undefined Symbols for architecture x86_64:

Hello, I've got problems with programming "C" on my MacBook Air (Intel Prozessor).


When I write following code:


#include <stdio.h>


struct Haustier{

char tier [50];

char name [20];

int alter;

float groesse;

};

void printHaustier (struct Haustier h){

printf ("Das Haustier heißt %s, ist %i; Jahre alt und %.2f cm gross.", h.name, h.alter, h.groesse);

}

int main(){

struct Haustier h;

h.name[0]= 'f';

h.name[1]= 'l';

h.name[2]= 'o';

h.alter=55;

h.groesse= 6.22;

printfHaustier(h);

return 0;


}


It prints out following problems:


Undefined symbols for architecture x86_64:

"_main", referenced from:

<initial-undefines>

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)


As far as I've researched about problem, it seems to be the wrong installation path for my operating system. Something about the mixing of two different toolchains: C compiler and linker and runtime...? (actually I don't know anything about that, I am a bloody beginner).


The interesting thing is that I actually was careful about the operating system (Intel vs M1/M2 Chips) and installed as far as I know VisualStudioCode for architecture x86_64. And then adding the Install-packs: "Code runner" and "C/C++".


When I try another basic code like:

#include <stdio.h>

int main() {

printf("Hello World!");

return 0;

}


It actually prints out the "Hello World".



I don't know what I did wrong and how I could save that problem. Any Help? Thank you!

MacBook Air (2018 – 2020)

Posted on Jun 26, 2024 4:18 AM

Reply

Similar questions

2 replies

Jun 26, 2024 5:21 AM in response to tarunai_l

Hi,

Following faults make the error, Undefined Symbols for architecture x86_64:


1) The function is not defined.

2) The function name is wrong.

3) Variables are not defined.

4) Static members are not defined.

5) The header file is not included.

6) The external library is not linked.

7) C language and C++ codes are intermingled.

8) There is no template exited.


Jun 26, 2024 10:42 AM in response to tarunai_l

This compiles and runs cleanly on macOS Monterey 12.7.5 with X86_64 processor:


/* clang -O2 -o testit test.c */

#include <stdio.h>

struct Haustier{
        char tier [50];
        char name [20];
            int alter;
            float groesse;
};
   
void prtHaustier(struct Haustier h) {
    printf("Das Haustier heißt %s, ist %i; Jahre alt und %.2f cm gross.\n", h.name, h.alter, h.groesse);
    return;
}

int main(int argc, const char * argv[]) {
    struct Haustier h;
    h.name[0]= 'f';
    h.name[1]= 'l';
    h.name[2]= 'o';
    h.alter=55;
    h.groesse= 6.22;
    prtHaustier(h);

    return 0;
}

Use contemporary C constructs. Don't use command names as part of function names and pay attention to white space as I have done in the revision above.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Problem with programming "C" on MacBook Air (Intel Prozessor) "Undefined Symbols for architecture x86_64:

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.