Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I wrote a very simple (my first) c program.
when I compile it using the following command:
gcc test.c -o ./testI get these error messages:
/data1/AIPSDATA/cccOR2AB.o: In function `main':
/data1/AIPSDATA/cccOR2AB.o(.text+0xfe): undefined reference to `sqrt'
collect2: ld returned 1 exit statusAIPS is an astronomical data reduction software I installed a while back, and /data1/AIPSDATA/ is a subdirectory used to store AIPS file. It has nothing to do with this c program I've written.
I've also tried compiling using the following command:
g++ -lm test.c -o ./testThis gave me the following error messages:
/data1/AIPSDATA/ccmttbnu.o: In function `main':
/data1/AIPSDATA/ccmttbnu.o(.text+0xfe): undefined reference to `sqrt'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so: undefined reference to `cosh@GLIBC_2.0'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so: undefined reference to `cos@GLIBC_2.0'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so: undefined reference to `exp@GLIBC_2.0'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so: undefined reference to `sinh@GLIBC_2.0'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so: undefined reference to `sin@GLIBC_2.0'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/libstdc++.so: undefined reference to `log@GLIBC_2.0'
collect2: ld returned 1 exit statusCan anyone help with this mysterious problem?
Siow-Wang

are you in the right directory when you
compile? i use this command to compile: g++
-o test test.cpp ~ and then to run ./test

When I compiled the code (given below), I
was in the subdirectory where the code is located, which is /data1/n5775/. I have also sent the code to a friend's computer and was able to compile it successfully there.#include
#includeint main(void)
{
float vel1,vel2,ii,rms,ii_rms;
char l[80],offset[10];
int i;
FILE *fp,*fp2;fp = fopen("co10iram_integrated_intensity_table.dat","r");
fp2 = fopen("co10iram_rms_integrated_intensity.dat","w");/* bypassing file comments */
for (i=0; i18; ++1)
fgets(l,80,fp);/* reading in data and calculating rms of integrated intensity */
while (fgets(l,100,fp) != NULL)
{
sscanf(l,"%c %f %f %f %f",&offset,&vel1,&vel2,&ii,&rms);
ii_rms = sqrt((vel2-vel1)/3.269)*3.269*rms;
fprintf(fp2,"%c %f %f %f %f \n",&offset,&vel1,&vel2,&ii,&ii_rms);
}
}
Also, what's the math header file? (response 2)I don't understand the command g++ -o test test.cpp ~ (response 3). Pray explain.
Thanks very much.
Siow-Wang

#include
#includeint main(void)
{
float vel1,vel2,ii,rms,ii_rms;
char l[80],offset[10];
int i;
FILE *fp,*fp2;fp = fopen("co10iram_integrated_intensity_table.dat","r");
fp2 = fopen("co10iram_rms_integrated_intensity.dat","w");/* bypassing file comments */
for (i=0; i18; ++1)
fgets(l,80,fp);/* reading in data and calculating rms of integrated
intensity */while (fgets(l,100,fp) != NULL)
{
sscanf(l,"%c %f %f %f %f",&offset,&vel1,&vel2,&ii,&rms);
ii_rms = sqrt((vel2-vel1)/3.269)*3.269*rms;
fprint(fp2, "%c %f %f %f %f \n",&offset,&vel1,&vel2,&ii,&ii_rms);
}
}

sorry about the repeats, but I can't seem
to get the code printed out properly here.Anyway, the stdio.h and math.h were in the include statements where they should be.
Siow-Wang

I was refering to math.h...
I just noticed that your trig functions were bombing out... figured it wasn't included at first glance.Infinite Recursion

use g++ compiler instead of gcc or cc this should work.
Ertugrul
There are 10 types of people: those who understand binary and those who don't

![]() |
Server side scripting
|
undefined reference error...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |