Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined symbols for architecture x86_64 in C

Tags:

c

allegro5

Today I installed the Allegro game programming library for C and I’ve tried to include one of the header files but when I try to execute gcc -I./include example.c -o a.exe in the terminal, I keep on getting this error:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: __al_mangled_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas? I installed Allegro 5 using the instructions here: https://wiki.allegro.cc/index.php?title=Install_Allegro5_From_GIT/OSX

example.c code:

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, const char *argv[]){
    puts(“Hello, world!”);
    return 0;
}
like image 817
Calculus5000 Avatar asked Feb 10 '23 00:02

Calculus5000


1 Answers

You need to link your executable to Allegro.

According to the FAQ, you should add -lallegro to your compile command, or -lallegro -lallegro_main on OSX

You may need other flags, and Allegro 5 uses pkg-config instead of allegro-config, so do pkg-config allegro-5.0 allegro_main-5.0 --cflags --libs to find out.

You can combine this into a compiler command by using backticks, e.g.

$CC -W -Wall `pkg-config allegro-5.0 allegro_main-5.0 --cflags --libs` foo.c -o foo.exe
like image 171
Iskar Jarak Avatar answered Feb 11 '23 13:02

Iskar Jarak