Compile files in C using OS X

1

Two months ago I asked a question related to the compilation of multiple files in C, I'm using OS X, but for GNU / Linux it would be the same. My question is how to compile the following three files from the terminal: main.c racional.c racional.h

//Código racional.h

struct racional{
    int numerador;
    int denominador;
};

typedef struct racional RACIONAL;

//Definicion de operaciones

RACIONAL crear();
RACIONAL sumar(RACIONAL r, RACIONAL q);
void mostar(RACIONAL r);
void obtenerNum(RACIONAL r);
int obtenerDen(RACIONAL r);
//Código racional.c
#include <stdio.h>
#include "racional.h"
//Implementacion de operaciones

RACIONAL crear(){
    RACIONAL a;
    printf("Ingrese numerador: "); scanf("%d", &a.numerador);
    printf("Ingrese denominador: "); scanf("%d", &a.denominador);
return a;
}

RACIONAL sumar(RACIONAL r, RACIONAL q){
    RACIONAL a;
    a.numerador= r.numerador*q.denominador + q.numerador*r.denominador;
    a.denominador= r.denominador*q.denominador;
return a;
}

void mostar(RACIONAL r){
    printf("%d/%d\n", r.numerador, r.denominador);
}

int obtenerNum(RACIONAL r){
return r.numerador;
}

int obtenerDen(RACIONAL r){
return r.denominador;
}
//Código main.c
#include <stdio.h>
#include "racional.h"

int main(int argc, char const *argv[]){
    /* code */
    RACIONAL b, c, d;

    printf("Primer racional\n");
    b= crear();
    printf("Numerador ingresado: %d\n", obtenerNum(b));
    printf("Denominador ingresado: %d\n", obtenerDen(b));

    printf("Segundo rarcional \n");
    c= crear();
    printf("Numerador ingresado: %d\n", obtenerNum(c));
    printf("Denominador ingresado: %d\n", obtenerDen(c));

    printf("Suma\n");
    d= sumar(b,c);
    mostrar(d);

return 0;
} 

It does not work writing in the path where the file is in the terminal: gcc -o rational output.h rational.c main.c and then ./out I get the following error: clang: error: can not specify -or when generating multiple output files Thank you very much for your time.

    
asked by Fesa 07.05.2016 в 23:47
source

1 answer

0

The GCC command that has OS X is called LLVM-GCC and is usually customized by Apple for the use of Xcode, so I suggest using the clang command, more information about the differences between them here

Going to the solution, first of all there are a couple of errors:

  • It is necessary to change void obtenerNum(RACIONAL r); to int obtenerNum(RACIONAL r); in file racional.h

  • It is necessary to change mostar(RACIONAL r) to mostrar(RACIONAL r) in the files racional.h and racional.c since that is how it is used in main.c

Finally, use this command in the folder of the files to compile:

clang racional.c main.c -o salida

And this to execute it

./salida

I hope it helps:)

    
answered by 08.05.2016 / 03:25
source