Hi,
I seem to be having trouble with some of my math functions (pow, sqrt,
acos). They're the only ones I use in my code and they prevent the program
from compiling. I get a "undefined reference to 'pow'" error. Here is the
relevant portion of my code.
Your help would be appreciated. Thanks!
* Genetic Algorithm module
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "string.h"
/* GetSD
*
* This function returns the standard deviation of the feature vectors
* in a dataT * array.
*/
static double GetSD(dataT *dataArr[], int data_size, int features[], double
mean[]) {
int i, j;
double data_vect[GENES_PER_CHROM], data_sum, mean_sum, ang_sum, dotprod,
data_norm, mean_norm, angle;
double sd;
ang_sum = 0;
for(i = 0; i < data_size; i++) {
for(j = 0; j < GENES_PER_CHROM ; j++) {
data_vect[j] = dataArr[i]->val[(features[j])];
}
// get dot product of the two vectors
dotprod = 0;
for(j = 0; j < GENES_PER_CHROM ; j++) {
dotprod += data_vect[j] * mean[j];
}
// get the norms
data_sum = 0;
mean_sum = 0;
for(j = 0; j < GENES_PER_CHROM ; j++) {
data_sum += pow(data_vect[j], 2);
mean_sum += pow(mean[j], 2);
}
data_norm = sqrt(data_sum);
mean_norm = sqrt(mean_sum);
// compute the angle
angle = acos(dotprod/(data_norm * mean_norm));
ang_sum += pow(angle, 2);
}
sd = sqrt(ang_sum / (data_size - 1));
return sd;
} 33 22066
Darius Fatakia <da************ @yahoo.com> wrote: Hi,
I seem to be having trouble with some of my math functions (pow, sqrt, acos). They're the only ones I use in my code and they prevent the program from compiling. I get a "undefined reference to 'pow'" error. Here is the relevant portion of my code.
You are most likely having a linking problem. Read your system
documentation to find out how to link in the math library.
<OT> Appending -lm to your compile line might work. </OT>
Alex
Darius Fatakia wrote: I seem to be having trouble with some of my math functions (pow, sqrt, acos). They're the only ones I use in my code and they prevent the program from compiling. I get a "undefined reference to 'pow'" error. Here is the relevant portion of my code.
cat gam.c
typedef struct dataT {
double* val;
} dataT;
#define GENES_PER_CHROM 1024
/*
* Genetic Algorithm module
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "string.h"
/* GetSD
*
* This function returns the standard deviation
* of the feature vectors in a dataT* array.
*/
static
double GetSD(dataT* dataArr[],
int data_size, int features[], double mean[]) {
double data_vect[GENES_PER_CHROM];
double ang_sum = 0.0;
for(int i = 0; i < data_size; ++i) {
for(int j = 0; j < GENES_PER_CHROM ; ++j) {
data_vect[j] = dataArr[i]->val[(features[j])];
}
// get dot product of the two vectors
double dotprod = 0.0;
for(int j = 0; j < GENES_PER_CHROM ; ++j) {
dotprod += data_vect[j]*mean[j];
}
// get the norms
double data_sum = 0.0;
double mean_sum = 0.0;
for(int j = 0; j < GENES_PER_CHROM ; ++j) {
data_sum += pow(data_vect[j], 2);
mean_sum += pow(mean[j], 2);
}
double data_norm = sqrt(data_sum);
double mean_norm = sqrt(mean_sum);
// compute the angle
double angle = acos(dotprod/(data_norm*mean _norm));
ang_sum += pow(angle, 2);
}
return sqrt(ang_sum/(data_size - 1));
}
int main(int argc, char* argv[]) {
dataT* dataArr[GENES_PER_CHROM];
int data_size = 1024;
int features[1024];
double mean[GENES_PER_CHROM];
GetSD(dataArr, data_size, features, mean);
return 0;
}
gcc -Wall -std=c99 -pedantic -o gam gam.c -lm
If you include math.h, you need to link in libm.a with the -lm option.
On Mon, 24 Nov 2003 16:52:07 -0800, Darius Fatakia wrote: Hi,
I seem to be having trouble with some of my math functions (pow, sqrt, acos). They're the only ones I use in my code and they prevent the program from compiling. I get a "undefined reference to 'pow'" error. Here is the relevant portion of my code.
Sounds like a linker error - are you linking the math libraries? There's
a certain, popular compiler, especially widely used in the Linux world,
which has the terminally brain-dead habit of not including the math
libraries by default. Assuming you're using this compiler, try something
like this:
gcc -lm file.c
I wonder how many HUNDREDS of times I have seen this question
pop up.
Are there any gcc fans out here?
Wouldn't it be time to include that library as a default library????
eh? !!!
This bug is similar to the make utility bug. Tabs are used as
separator
in "make", and the makefile will not work if they are substituted by
spaces!
This makes every novice spend hours trying to find out why two
makefiles that look the
same do not work.
In <pa************ *************** *@lightspeed.bc .ca> Kelsey Bjarnason <ke*****@lights peed.bc.ca> writes: On Mon, 24 Nov 2003 16:52:07 -0800, Darius Fatakia wrote:
I seem to be having trouble with some of my math functions (pow, sqrt, acos). They're the only ones I use in my code and they prevent the program from compiling. I get a "undefined reference to 'pow'" error. Here is the relevant portion of my code.
Sounds like a linker error - are you linking the math libraries? There's a certain, popular compiler, especially widely used in the Linux world, which has the terminally brain-dead habit of not including the math libraries by default. Assuming you're using this compiler, try something like this:
gcc -lm file.c
gcc merely follows the common Unix convention, established by a certain
Dennis M. Ritchie.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
In <bp**********@n ews-reader3.wanadoo .fr> "jacob navia" <ja***@jacob.re mcomp.fr> writes: I wonder how many HUNDREDS of times I have seen this question pop up.
Are there any gcc fans out here?
Why should gcc behave differently than most other Unix compilers?
Wouldn't it be time to include that library as a default library????
Nope, but it would be high time to include the contents of libm.a into
libc.a and provide an empty libm.a, for backward compatibility purposes.
The *good* reasons for keeping it separate have no longer been valid for
the last 15 years or so.
Which has precisely zilch to do with gcc or any other Unix compiler.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
On Tue, 25 Nov 2003 10:51:38 +0100, in comp.lang.c , "jacob navia"
<ja***@jacob.re mcomp.fr> wrote: I wonder how many HUNDREDS of times I have seen this question pop up.
thats why its a FAQ....
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
On Mon, 24 Nov 2003 16:52:07 -0800, in comp.lang.c , "Darius Fatakia"
<da************ @yahoo.com> wrote: "undefined reference to 'pow'" error.
This is a FAQ. Please read the FAQs
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
jacob navia wrote:
[ snip ] This bug is similar to the make utility bug. Tabs are used as separator in "make", and the makefile will not work if they are substituted by spaces!
This makes every novice spend hours trying to find out why two makefiles that look the same do not work.
I'm not sure I agree that it's a bug but it is annoying. make simply
uses TAB as a separator between the Rule and the Command portions of a
statement. As I use edit.com with tabs set to 3 this annoyed the hell
out of me too. Reading the info file on make one day (I'm surprised how
little I do this and how much I should) I read that ';' semicolon is
also a Rule / Command separator. How 'bout this..
# Use GNU make to build an executable for testing GE.
cc=gcc
obj=ge.o main.o
exe=main.exe
opt=-W -Wall -ansi -pedantic -O2 -c
# Note that semicolon (not TAB) separates Rule from Command on a line.
$(exe) : $(obj) ; $(cc) -s $(obj) -o $(exe)
ge.o : ge.c ; $(cc) $(opt) ge.c
main.o : main.c ge.h ; $(cc) $(opt) main.c
Live and learn.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eshrath |
last post by:
Hi,
What I am trying to do:
=======================
I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are writing one object in C# which will take the entire table tag
contents and renders. Ie., we need to pass "<table>…………
<thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
|
by: Donald Firesmith |
last post by:
I am having trouble having Google Adsense code stored in XSL converted
properly into HTML. The <> unfortunately become < and > and then
no longer work.
XSL code is:
<script type="text/javascript">
<!]>
</script>
<script type="text/javascript"
|
by: Tuckers |
last post by:
My question is, if I have created my own library which lives in its own
install directory, to refer to its header file is it better to use
#include "MyLibrary.h"
or
#include <MyLibrary.h>
Assume that this library will be used by other groups. I think the answer
|
by: John B. |
last post by:
I'm self teaching myself C on a Linux box but I can't get a simple program
to recognize math functions. I start the program with:
#include <stdio.h>
#include <math.h> but when I compile the program, it does not
recognize sin(x); or pow(x,y) etc, in any equation.
/usr/include does have a math.h file. Any help or things to try would
be greatly appreciated!!!!. (I do alot of graphic things with trig.)
thanks ...
|
by: bill |
last post by:
Forget the exact definition of difference between,
#include <foo.h>
and
#include "bar.h"
Normally foo.h is a standard header file, so it's path is not defined
in compiler option, but I am curious how compiler find it.
| |
by: Jofio |
last post by:
I have 3 files, namely:
dArray.h
dArray.cp
TestdArray.cpp
Problem is when I compile the 'main' program - TestdArray.cpp - , it
(the compiller) produces the following error:
'Unable to open include file 'dArray.h'
'Unable to open include file'dArray.cp'
|
by: ajay2552 |
last post by:
Hi,
I have a query.
All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it?
One method is to use <, > ,<Company> to display '<', '>' and '<Company>' respectively.
But is there any freeware code available which could implement the above functionality without having to use >,< and such stuff???
|
by: Sebastian Faust |
last post by:
Hi,
I hava a somehow strange problem. I hope I am not wrong in this group;
if this is the case please let me know.
I am trying to compile a rather simple C program. As long as I use:
#include <extp.h>
gcc tells me that he cannot find extp.h.
As soon as I write
#include "extp.h"
|
by: Michael |
last post by:
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?
Thanks,
M. McDonnell
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |