Computing.Net > Forums > Programming > problem in compiling c program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

problem in compiling c program

Reply to Message Icon

Name: Siow-Wang Lee
Date: August 6, 2003 at 15:00:18 Pacific
OS: RedHat Linux 7.1
CPU/Ram: AMU1.4GHz/256kb
Comment:

I wrote a very simple (my first) c program.
when I compile it using the following command:
gcc test.c -o ./test

I 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 status

AIPS 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 ./test

This 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 status

Can anyone help with this mysterious problem?

Siow-Wang




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: August 6, 2003 at 15:59:10 Pacific
Reply:

It appears that it's trying to link the cccOR2AB.o file.

Can you show us the code for test.c?


0

Response Number 2
Name: Infinite Recursion
Date: August 6, 2003 at 20:03:15 Pacific
Reply:

Just at a glance... it looks like you are missing the math header file.

Infinite Recursion


0

Response Number 3
Name: cheezeWhiz
Date: August 7, 2003 at 07:48:01 Pacific
Reply:

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


0

Response Number 4
Name: Siow-Wang Lee
Date: August 8, 2003 at 06:32:24 Pacific
Reply:

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
#include

int 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


0

Response Number 5
Name: Siow-Wang Lee
Date: August 8, 2003 at 06:52:57 Pacific
Reply:

#include
#include

int 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);
}
}


0

Related Posts

See More



Response Number 6
Name: Siow-Wang Lee
Date: August 8, 2003 at 06:55:18 Pacific
Reply:

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


0

Response Number 7
Name: Infinite Recursion
Date: August 8, 2003 at 10:18:32 Pacific
Reply:

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


0

Response Number 8
Name: Ertugrul
Date: September 2, 2003 at 14:09:07 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Server side scripting undefined reference error...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: problem in compiling c program

Problems in compiling D-ITG www.computing.net/answers/programming/problems-in-compiling-ditg/15086.html

simulation of wc in a c program www.computing.net/answers/programming/simulation-of-wc-in-a-c-program/13560.html

Compile C program www.computing.net/answers/programming/compile-c-program/613.html