u/GreenAnonymous5

Undefined reference to pow in Visual Studio Code on Linux Mint Cinnamon (math.h is already in the code, and the fixes I found in the internet don't work)

Undefined reference to pow in Visual Studio Code on Linux Mint Cinnamon (math.h is already in the code, and the fixes I found in the internet don't work)

I'm trying to run a code from my teacher's university powerpoint. The file's name is cap4.c Here's the code:

/* Fig. 4.6: fig04_06.c - pag21
   Calculating compound interest*/
#include <stdio.h>
#include <math.h>
int main()
{
   double amount;  //amount on deposit
   double principal = 1000.0;  //starting principal
   double rate = .05;  //interest rate
   int year;  //year counter


   
//output table column head
   printf("%4s %21s \n", "Anno", "Quantita' nel deposito");


   
//calcola la quantità nel deposito di ciascuno dei dieci anni
   for (year = 1; year <= 10; year++) {
   
      
//calcola la nuova quantità per l'anno specificato
      amount = principal * pow(1.0 + rate, year);


      
//output one table row
      printf("%4d%21.2f\n", year, amount); }  //end for
   
   return 0; }  //indica che il programma è chiuso con successo

This is the code's output:

/usr/bin/ld: /tmp/ccHYidXD.o: in the function `main':
tempCodeRunnerFile.c:(.text+0x80): undefined reference to `pow'
collect2: error: ld returned 1 exit status

I tried a fix from Its Linux FOSS and Stack Overflow :

$ gcc -o cap4 cap4.c -lm

Then this fix from LinuxVox:

gcc your_program.c -o your_program -lm

and this is what both fixes return (I translated the "File or directory doesn't exist" text myself):

cc1: fatal error: cap4.c: File or directory doesn't exist
compilation terminated.

I can't seem to find another solution to this, any other way to fix it?

EDIT: a comment reported I accidentally pasted the same code twice, I fixed it now. Also added a step before the fixes

u/GreenAnonymous5 — 6 days ago
▲ 0 r/oneui

I'm currently on OneUI 7.0 and I don't want to update to OneUI 8+ at all, how do I disable the notification that tells me to update?

EDIT: okay, thank you for the answers.

reddit.com
u/GreenAnonymous5 — 7 days ago