Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Problem with using <math.h> in Eclipse for C/C++
Problem with using <math.h> in Eclipse for C/C++ [message #1719597] Sat, 09 January 2016 14:46 Go to next message
Alina K. is currently offline Alina K.Friend
Messages: 2
Registered: January 2016
Junior Member
I've installed Linux Mint 17 recently. And now I've problem with using functions of <math.h>(errors like "undefined reference to sin"). I've tried to change settings of linker: Project->Properties->C/C++ Build-> Settings->Cross Gcc Linker->...Comand: gcc -Wall -o ranges ranges.c -lm(my source file with main function is named ranges.c) and received message:
"make all
Building target: ranges
Invoking: Cross GCC Linker
gcc -Wall -o ranges ranges.c -lm -o "ranges" ./src/ranges.o
gcc: error: ranges.c: No such file or directory
make: *** [ranges] Error1
17:19:49 Build Finished (took 156ms)"

Then I've tried to describe full path to my source file: ...Gcc Linker->...Comand: gcc -Wall -o ranges /home/alina/workspace/ranges/src/ranges.c -lm and received message:
"make all
Building target: ranges
Invoking: Cross GCC Linker
gcc -Wall -o ranges /home/alina/workspace/ranges/src/ranges.c -lm -o "ranges" ./src/ranges.o
./src/ranges.o: In function `main':
/home/alina/workspace/ranges/Debug/../src/ranges.c:5: multiple definition of `main'
/tmp/ccF6ydSp.o:ranges.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [ranges] Error 1
17:28:46 Build Finished (took 126ms)"

But I've only one main function! Shocked
this is my source file:
#include <stdio.h>
#include <math.h>

int main() {
int i, n = 2;
float s = 0.0, a = 0.0;

for (i = 1; i <= n; i++) {
a += sin(i);
s += 1.0 / a;
}
printf ("%.3f", s);
return 0;
}
With projects that don't contain mathematical functions Eclipse works correctly. How can I solve this problem so I can build projects with <math.h> in Eclipse IDE?
Re: Problem with using &lt;math.h&gt; in Eclipse for C/C++ [message #1719611 is a reply to message #1719597] Sat, 09 January 2016 23:24 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

You'll want to post in the Eclipse CDT forum.
Previous Topic:Setup a (ARM) cross toolchain for Linux
Next Topic:Problem debugging a wxWidget application with Eclipse
Goto Forum:
  


Current Time: Thu Mar 28 18:38:21 GMT 2024

Powered by FUDForum. Page generated in 0.04180 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top