How can I solve an "indefinite reference"?

Asked

Viewed 5,250 times

1

I’m starting now in this life of programmer and I’m trying to perform a program for physics class but at the time of compiling the file is turning me this message... reach. c:(.text+0x68): undefined reference to cos' alcance.c:(.text+0x93): referência indefinida parasin' collect2: error: Ld returned 1 Exit status

I’m using Emacs... gcc -lm -o range. c, I must send other information??


This is the part referring to consseno and sine Rx=0.0; Ry=0.0; vx=v0*cos(theta*3141592/180.0); Vy=v0*sin(theta*3.141592/180.0);
I must do the double cos, and double sin?


#include <stdio.h>
#include <math.h>
 main () 
{
  double ry;
  double rx;
  double vx;
  double vy;
  double ax;
  double ay;
  double dt;
  double t;
  double g;
  double v0;
  double theta;
  double b; // [1/ms]coeficiente de arrasto
  double  dtheta; // angulo de lancamento

  g=-10;
  dt=0.1;// 
  v0=100;// velocidade inicial
  dtheta=1;// angulo de lançamente
  b=1;// coeficiente de arrato
  for (theta=0;theta<=90;theta=theta=dtheta){
    rx=0.0;
  ry=0.0;
  vx=v0*cos(theta*3141592/180.0);
  vy=v0*sin(theta*3.141592/180.0);

  
 for(t=0;t<=500;t=t+dt){

   if(ry<0.0)break;
   ax=0.0-b*vx;
   ay=-g-b*vy;
   rx=rx+vx*dt;
   ry=ry+vy*dt;
   vx=vx=ax*dt;
   vy=vy+ay*dt;
 }
#include <math.h>
 printf("%f %f %f %f %f %f\n",theta,t,rx,ry,vx,vy);
  }  
  return 0;
}

  • You tried to compile by putting -lm at the end as suggested by @pmg ?

1 answer

3

Put libraries at the end of the command

gcc -o alcance alcance.c -lm

According to the gcc manual

[...] It makes a Difference Where in the command you write this option [...]

  • How do I end the library? it’s already at the top #include <studio. h> #include <Math. h>

  • I’m writing a program in C++ to a microcontroller using the avr-gcc compiler. I am having the following error: neuronio.cpp:(.text._ZN8neuronioC2Eii+0x42): referência indefinida para operator new[](unsigned int). Can I even use a new one? Some people have told me that it is impossible to create an object in a µC, but I am convinced that I can do it. Could you help me?

  • 2

    in the end of command, at the command line. Instead of gcc -lm ... uses gcc ... -lm

  • made this library bid, "File or directory not found"

  • @Avelino If in doubt, ask a new question on the site. [pt.so] does not work as a traditional forum. Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.