0

I am learning for fun with building my own matrix and im on my Mac is the only computer I have and I dont want to go through Virtual environment just to play around with matrix on Mac. Is there a way or no is what I will like to find out.

int
main(int argc, char **argv) {
    
    if (!init_ui()) {
        return EXIT_FAILURE;
    }
    
    matrix_init();
    
    for (int i = 0; i < ITERATIONS; i++) {
        matrix_update();
        show_matrix();
        usleep(REFRESH_DELAY);
    }
    
    
    return EXIT_SUCCESS;
}

Here is the init_ui() function

bool init_ui() {
    
    //set the matrix all to black
    //move this later to matrix.c
    for (int x = 0; x < MAXX; x++) {
        
        for (int y = 0; y < MAXY; y++) {
            matrix[x][y].char_value = 0;
            matrix[x][y].char_value = 0;
        }
    }
    
    //init curses
    uiwindow = initscr();
    if (uiwindow == NULL) return false;
    
    start_color();
    if (!has_colors() || !can_change_color() || COLOR_PAIRS < 6) {
        
        printf("Warning. Your terminal can't handle this program.\n");
        return false;
    }
    
    set_colors();
    
    return true;
}//end bool

Error :

clang -Wall -g main.o matrix.o ui.o -o mainapp
Undefined symbols for architecture x86_64:
  "_COLOR_PAIRS", referenced from:
      _init_ui in ui.o
  "_can_change_color", referenced from:
      _init_ui in ui.o
  "_delwin", referenced from:
      _cleanup_ui in ui.o
  "_endwin", referenced from:
      _cleanup_ui in ui.o
  "_has_colors", referenced from:
      _init_ui in ui.o
  "_init_color", referenced from:
      _set_colors in ui.o
  "_init_pair", referenced from:
      _set_colors in ui.o
  "_initscr", referenced from:
      _init_ui in ui.o
  "_start_color", referenced from:
      _init_ui in ui.o
  "_stdscr", referenced from:
      _cleanup_ui in ui.o
      _show_matrix in ui.o
  "_waddch", referenced from:
      _show_matrix in ui.o
  "_wcolor_set", referenced from:
      _show_matrix in ui.o
  "_wmove", referenced from:
      _show_matrix in ui.o
  "_wrefresh", referenced from:
      _cleanup_ui in ui.o
      _show_matrix in ui.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mainapp] Error 1

The init_ui() is not the only the problem here. I mean I fell in love with c so I can't stop coding in c even though I mastered python but c just took my attention. So idk I would love to know more than just write boring code

  • 2
    You're missing something like `-lncurses` in your compiler invocation to link with the library you are using. –  Mar 16 '21 at 20:45
  • I am taking systems programming class this semester. I finished my project and now I'm playing around with c and what you have just told me is kinda alien language right now. Can you please elaborate ? I mean I get what you are trying to say but little more information to understand clearly will help a lot. thank you though –  Mar 16 '21 at 20:52
  • Functions need to be implemented somewhere. Either by you directly in your code or in a library somewhere. `init_ui` is not in your code so it must be somewhere else and in this case it is in the ncurses library. `-lncurses` on the build command line tells the compiler to use that library. – kaylum Mar 16 '21 at 20:55
  • I added the init_ui() function for review but I am going over it myself right now –  Mar 16 '21 at 21:03
  • Major thing I would like to take from this question post is when this error is thrown: Undefined symbols for architecture x86_64: what should I think right away? I mean I do see but in general how should I target this problem? –  Mar 16 '21 at 21:10
  • 2
    This is a linker (`ld`) error meaning your program compiled fine, but was not able to be completed into an executable due to missing symbols. If you search online for the symbols in question, you should stumble onto something like this https://stackoverflow.com/questions/11954057/error-while-compiling-ncurses-app-on-mac-os-x –  Mar 16 '21 at 21:32
  • @dratenik Thank you so much. You were right -lncurses worked and everything compiled with 0 errors –  Mar 16 '21 at 22:43

1 Answers1

1

So to fix this error. The only thing needed was -lncurses which is explained @ Error while compiling ncurses app on Mac OS X

In my scenario I needed to compile as according shown below

mainapp: main.o matrix.o ui.o
    $(CC) $(CFLAGS) main.o matrix.o ui.o -o mainapp -lncurses

Thank you @dratenik && @kaylum