943,693 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 7223
  • C++ RSS
Dec 30th, 2007
0

gcc header files and math libary

Expand Post »
I am a new to linux and the gcc system I was just wondering if someone could answer a couple of questions about the including hearder files like the math.h file.

I was making a simple program and using some math trig functions. I keep getting the error cosf undefined text or some thing like that so I got to looking around online and found out it was a linker error. So I typed in the command

Gcc –o test test.c –lm

My question is do I have to add all the include files to the command line?
If not how do I know witch ones I do have to add to the line?
How do you add more then one-header file to the linker?

Does anyone know of a good online resource that would walk me through using the gcc complier.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
guy40az is offline Offline
51 posts
since Mar 2007
Dec 30th, 2007
0

Re: gcc header files and math libary

>My question is do I have to add all the include files to the command line?
You don't add headers (include files) on the command line. They're strictly for the compiler so that it has declarations for the names that will be linked in later. What you're doing is telling the linker to link with a specific library; in this case that library is the math library. For the most part the standard libraries are linked automagically, with the math library being an exception.

>Does anyone know of a good online resource that
>would walk me through using the gcc complier.
http://gcc.gnu.org/onlinedocs/
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Dec 30th, 2007
0

Re: gcc header files and math libary

Hi,

I happen to bump around wiht this problem too.

I have a .c file and multiple header files.

After executing the -lm flag, I managed to get the executable file. However, when I tried to ./a.out, the compiler just hangs there without any response.

The motivation for me to execute ./a.out is I would like the gcc to generate gcda file for me from gcov.

Please help. Thanks.

-Jason
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ahjiefreak is offline Offline
11 posts
since Dec 2007
Dec 31st, 2007
0

Re: gcc header files and math libary

> the compiler just hangs there without any response.
The compiler is all done if you've got an a.out file. If that isn't responding, it can only be your source code which is at fault. You need to post some for further enlightenment.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Dec 31st, 2007
0

Re: gcc header files and math libary

The source code works ok, its just when I compile using

Gcc test.c I get the linker error but when I use the

Gcc –o test test.c –lm the –lm fixes the problem.

I was just wondering if the math library is the only library I had to add to the
Command line.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
guy40az is offline Offline
51 posts
since Mar 2007
Dec 31st, 2007
0

Re: gcc header files and math libary

> I was just wondering if the math library is the only library I had to add to the
> Command line.
It's the only one of the standard header files you can include.
But if you include other non-standard headers, you'll need to link with other non-standard libraries as well.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help me with classes
Next Thread in C++ Forum Timeline: having trouble picking a return type





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC