0

I just started using Code Runner quite recently and for some reason it won't compile my C program.

The Error is as followed:

Undefined symbols for architecture x86_64:
"_rush", referenced from:
  _main in main-f9aa06.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

main.c

#include <stdio.h>

int ft_putchar(char c);
void rush(int x, int y);

int main(void){
    int x, y;
    scanf("%i", &x);
    scanf("%i", &y);
    rush(x, y);
    return (0);
}

ftputchar.c

#include <unistd.h>

int ft_putchar(char c){
    write(1, &c, 1);
    return (0);
}

rush.c

int ft_putchar(char c);

void top_bottom(int n){
    int i = 0;
    ft_putchar('A');
    while(i < n - 2){
        ft_putchar('B');
        i++;
    }
    ft_putchar('C');
    ft_putchar('\n');
}

void rush(int x, int y){
    if(x > 1 && y > 1) {
        int j, i;
        j = 0;
        i = 0;
        top_bottom(x);
        while (i < y - 2) {
            ft_putchar('B');
            while (j < x - 2){
                ft_putchar(' ');
                j++;
            }
            j = 0;
            ft_putchar('B');
            ft_putchar('\n');
            i++;
        }
        top_bottom(x);
    }
    if(x < 1 || y < 1){
        return ;
    }
    if(x == 1 && y == 1){
        ft_putchar('A');
        ft_putchar('\n');
    }
    if(x > 1 && y == 1){
        top_bottom_03(x);
    }
    if(x == 1 && y > 1){
        int i = 0;
        ft_putchar('A');
        ft_putchar('\n');
        while(i < y - 2){
            ft_putchar('B');
            ft_putchar('\n');
            i++;
        }
        ft_putchar('A');
        ft_putchar('\n');
    }
}

Code Runner v2.3

However, when I used XCode to compile and run the code it works perfectly fine.

Also if I place everything into the main.c file then the code runs and compiles perfectly.

  • probably because you're not linking with the proper object set, forgetting `rush.c`. Did you add it to your project? – Jean-François Fabre Jul 31 '17 at 07:47
  • just having the files in the same directory in an xcode project was enough for it to run and compile perfectly. I didn't need to use header files and include them. @Jean-FrançoisFabre – Asoka Wotulo Jul 31 '17 at 08:09
  • are you using -g when you compile? – pierreafranck Jul 31 '17 at 10:02
  • Do you understand that the error message is from the linker, not the compiler? usually the missing x86 error message means that the link statement is missing some library or some object file – user3629249 Aug 01 '17 at 13:08

0 Answers0