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.

>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/

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

> 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.

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.

> 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.