1

I'm a begginer in C programm and I've tried to do some exercices in order to learn how to programm. I did a lot of small and simple programms, but one of this I had a trouble. I can't compile it. I'm a linux user (linux mint) and I'm using VS Code too. The terminal show me a trouble with the 'ceil'. How is the right way to use the 'ceil'? Someone can help me? Many thanks.

You can see my code below:

#include <stdio.h>
#include <math.h>

int main(void){

    float pi = 3.14159;
    float raio, area, renTinta, qtdTinta, qtdLata;
    float arredonda_pcima = 0.0;

    printf("\nQual o raio da mesa?(medida em metros)\n");
    scanf("%f", &raio);
    printf("\nQual o rendimento da tinta?(padrão 5m/L\n");
    scanf("%f", &renTinta); 

    area = pi * ( raio * raio );

    qtdTinta = area / renTinta;
    qtdLata = qtdTinta / 10;
    arredonda_pcima = ceil(qtdLata);

    printf("\npara uma mesa de raio %.2f e área de %.2f será consumido %.2f de tinta e será(ão) necessária(as) %.0f latas\n\n", raio, area, qtdTinta, arredonda_pcima );


    return 0;
}

I receive the message by terminal...

Executing task: /usr/bin/gcc -g '/home/gilmar/Documents/Projeto FAC em C/fac16.c' -o '/home/gilmar/Documents/Projeto FAC em C/fac16' <

/tmp/cctqUJ2D.o: In function main': /home/gilmar/Documents/Projeto FAC em C/fac16.c:19: undefined reference toceil' collect2: error: ld returned 1 exit status The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Mureinik
  • 297,002
  • 52
  • 306
  • 350

1 Answers1

0

You are using the function in the right way, the problem is that the compiler can't find the ceil() function, probaly due to linking errors with the <math.h> library. If you're compiling from terminal, as others suggested, try to put -lm to the end of the line ("undefined reference to `pow'" even with math.h and the library link -lm for a detailed explanation). Otherwise, if you're trying to run it on VS Code, check if you have included the library in your project (go to the "Properties" tab and try to find something like "Include Directories".

  • Many thanks @NotAnotherSystem. I managed to compile using -lm at the end of the command in the terminal. I will study the -lm option for an upcoming occasion. Command used by terminal ~$ gcc fac16.c -o fac 16 -lm. – gilrsantana Mar 14 '20 at 18:18