Hi again,
I am new to compiling C programs in Linux/Unix. I wanted to compile a
program by using gcc, but it turned out that gcc does not know where to
locate the library being called.
The program is as follows,
#include <math.h>
int main()
{
double ss;
double ff;
ss=1.0;
ff=sin(ss);
printf("%6.4f\n",ff);
return 0;
}
The error message is,
/tmp/ccIV3yAb.o: In function `main':
/tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'
The command I used to compile is
gcc test.c
Could anyone please let me know where I did wrong? Thanks!
Fan 7 2190
Fan Zhang wrote: The error message is,
/tmp/ccIV3yAb.o: In function `main': /tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'
The command I used to compile is gcc test.c
Could anyone please let me know where I did wrong? Thanks!
You need to link with the math library which is called libm
so,
gcc test.c -lm
comp.os.linux.development.apps or comp.unix.programmer
is probably more appropriate for this Q though.
On Tue, 12 Oct 2004, Fan Zhang wrote: /tmp/ccIV3yAb.o: In function `main': /tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'
The command I used to compile is gcc test.c
This is practically word-for-word a FAQ. http://www.eskimo.com/~scs/C-faq/q14.3.html
Read the whole thing.
-Arthur
Fan Zhang wrote: I am new to compiling C programs in Linux/Unix. I wanted to compile a program by using gcc but it turned out that gcc does not know where to locate the library being called.
The program is as follows,
#include <math.h> int main() { double ss; double ff; ss=1.0; ff=sin(ss); printf("%6.4f\n",ff); return 0; }
The error message is,
/tmp/ccIV3yAb.o: In function `main': /tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'
The command I used to compile is gcc test.c
Could anyone please let me know where I did wrong? Thanks!
gcc test.c -lm
"Fan Zhang" <fa******@sas.upenn.edu> writes: I am new to compiling C programs in Linux/Unix. I wanted to compile a program by using gcc, but it turned out that gcc does not know where to locate the library being called. The command I used to compile is gcc test.c. Could anyone please let me know where I did wrong? Thanks!
See http://www.network-theory.co.uk/docs...cintro_16.html
for information on linking with external libraries with gcc.
--
Brian Gough
Network Theory Ltd,
Publishing "An Introduction to GCC" --- http://www.network-theory.co.uk/gcc/
In <87************@network-theory.co.uk> Brian Gough <bj*@network-theory.co.uk> writes: "Fan Zhang" <fa******@sas.upenn.edu> writes:
I am new to compiling C programs in Linux/Unix. I wanted to compile a program by using gcc, but it turned out that gcc does not know where to locate the library being called. The command I used to compile is gcc test.c. Could anyone please let me know where I did wrong? Thanks!
See http://www.network-theory.co.uk/docs...cintro_16.html for information on linking with external libraries with gcc.
Except that the sin function has nothing to do with *any* external
library: it's part of the standard C library.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
On Tue, 12 Oct 2004 18:25:30 -0400, "Fan Zhang"
<fa******@sas.upenn.edu> wrote in comp.lang.c: Hi again,
I am new to compiling C programs in Linux/Unix. I wanted to compile a program by using gcc, but it turned out that gcc does not know where to locate the library being called.
Linux is not UNIX, UNIX is not Linux.
The program is as follows,
#include <math.h> int main() { double ss; double ff; ss=1.0; ff=sin(ss); printf("%6.4f\n",ff); return 0; }
The error message is,
/tmp/ccIV3yAb.o: In function `main': /tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'
The command I used to compile is gcc test.c
Could anyone please let me know where I did wrong? Thanks!
Fan
Despite the fact that Linux is not UNIX, gcc on Linux continues the
old UNIX tradition of pretending that part of the standard C library
is not part of the standard C library.
UNIX elitists do not like to make things easy for the uninitiated,
unwashed masses, even when the reason for a particular piece of
stupidity has been obsolete for 20 years.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jack Klein wrote: On Tue, 12 Oct 2004 18:25:30 -0400, "Fan Zhang" <fa******@sas.upenn.edu> wrote in comp.lang.c:
Hi again,
I am new to compiling C programs in Linux/Unix. I wanted to compile a program by using gcc, but it turned out that gcc does not know where to locate the library being called.
Linux is not UNIX, UNIX is not Linux.
The program is as follows,
#include <math.h> int main() { double ss; double ff; ss=1.0; ff=sin(ss); printf("%6.4f\n",ff); return 0; }
The error message is,
/tmp/ccIV3yAb.o: In function `main': /tmp/ccIV3yAb.o(.text+0x1e): undefined reference to `sin'
The command I used to compile is gcc test.c
try this gcc -Wall -lm test.c This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jhuola Hoptire |
last post by:
Just installed J2RE 1.4.2 on a Linux server. I am very
knew to the POSIX world.
I couldn't dig-up much in the docs or via google about
the following:
1 - Is there a standard way to make sure...
|
by: Eric Raymond |
last post by:
When installing the rpms (or the tar file) onto Red Hat Enteprise
Linux AS Beta 1 (Taroon), we get the follwing error:
Installing all prepared tables
/usr/bin/mysql_install_db: line 1: 7690...
|
by: gnu |
last post by:
Rationale to use Linux
=======================
- I can't afford paying for $199 for the license of an OS that's
arguably better thank Linux for each of 10 computers I have.
- I want to be...
|
by: Travis 'Bailo' Bickel |
last post by:
Lately, I have been having a bear of a time trying to acquire a Linux driver
for my S3/ProSavage chipset -- but that quest is now almost at an end as I
have located a noble band of people who are...
|
by: srihari |
last post by:
Hai,
I am trying to install IBM DB2 8.1 on Red Hat linux 8.0. My
machine is Intel XEON 64bit. The installation went well except for the
creation of tools catalog. When I tried to install the tools...
|
by: Zorba.GR |
last post by:
IBM DB2 Connect Enterprise Edition v8.2, other IBM DB2 (32 bit, 64
bit) (MULTiOS, Windows, Linux, Solaris), IBM iSoft Commerce Suite
Server Enterprise v3.2.01, IBM Tivoli Storage Resource Manager...
|
by: cranium.2003 |
last post by:
hi,
Here is my code
#include <iostream.h>
int main()
{
cout <<"HI";
return 0;
}
and using following command to compile a C++ program
g++ ex1.cpp -o ex1
|
by: rada.lambretha |
last post by:
Configuring Linux as a Firewall
* Making installation choices
* Introducing iptables
* Using iptables commands
* Simplifying things with firewall GUIs
* Adding proxy functionality
As...
|
by: Nepomuk |
last post by:
You might have heard about Linux, but you don't know what it is? Or you know a few things about it, but they terrify you? Well, then this article is for you. Don't be afraid - Everyone can use Linux!...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |