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

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

problem in compiling c program

Reply to Message Icon

Original Message
Name: Siow-Wang Lee
Date: August 6, 2003 at 15:00:18 Pacific
Subject: problem in compiling c program
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



Report Offensive Message For Removal


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?


Report Offensive Follow Up For Removal

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


Report Offensive Follow Up For Removal

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


Report Offensive Follow Up For Removal

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


Report Offensive Follow Up For Removal

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


Report Offensive Follow Up For Removal


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


Report Offensive Follow Up For Removal

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


Report Offensive Follow Up For Removal

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


Report Offensive Follow Up For Removal






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



Results for: problem in compiling c program

Problems in compiling D-ITG
    Summary: Hi all, I have some problems in compiling Distributed Internet Traffic Generator (D-ITG) on an Ubuntu machine. The Generator is free and you can find it at http://www.grid.unina.it/software/I... When ...
www.computing.net/answers/programming/problems-in-compiling-ditg/15086.html

simulation of wc in a c program
    Summary: Hy guys!I have a little problem.I have to simulate the linux wc comand in a c program.I`ve figured out how to count the lines and "\n" but the counting of the wors is giving me a headake.Please help!I...
www.computing.net/answers/programming/simulation-of-wc-in-a-c-program/13560.html

Compile C program
    Summary: I want to compile C program in UNIX, where can I get the compiler? ...
www.computing.net/answers/programming/compile-c-program/613.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History






Data Recovery Software