Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Referencia indefinida a 'sin' al pasar variable en lugar de constante

Tenía un código que funcionaba perfectamente en Windows, pero cuando intenté compilarlo en Linux, recibí un error. Descubrí que el problema está en la función sin() .

Si le paso un número constante directamente, funciona bien:

 #include <stdio.h> #include <math.h> int main(void) { float y = sin(1.57); printf("sin(1.57) = %f", y); return 0; }

Salida 1 :

 sin(1.57) = 1.000000

Pero cuando le paso una variable me sale un error:

 #include <stdio.h> #include <math.h> int main(void) { float x = 1.5; float y = sin(x); printf("sin(%f) = %f", x, y); return 0; }

Salida 2 :

 /tmp/ccfFXUZS.o: In function `main': source-bcfaa9ff162b:(.text+0x1a): undefined reference to `sin' collect2: error: ld returned 1 exit status
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

En algunos sistemas, las funciones matemáticas están en una biblioteca separada, que debe vincularse explícitamente. Simplemente pase la opción -lm al compilar (vincular) su programa, y todo debería funcionar.

La razón por la que funciona el primero es porque el compilador conoce el pecado y optimizó todo a una constante; en realidad, no necesita llamar a la función sin.

over 4 years ago · Santiago Trujillo Report

0

Necesita vincular con -lm .

No sé por qué funciona el primer ejemplo, ¿tal vez algunas optimizaciones?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!