Source string Read only

(itstool) path: informalexample/programlisting
Context English State
This will both produce an executable <filename>foobar</filename> from the C++ source file <filename></filename>.
Common <command>cc</command> Queries and Problems
I am trying to write a program which uses the <function>sin()</function> function and I get an error like this. What does it mean?
/var/tmp/cc0143941.o: Undefined symbol `_sin' referenced from text segment
When using mathematical functions like <function>sin()</function>, you have to tell <command>cc</command> to link in the math library, like so:
All right, I wrote this simple program to practice using <option>-lm</option>. All it does is raise 2.1 to the power of 6.
#include &lt;stdio.h&gt;

int main() {
float f;

f = pow(2.1, 6);
printf("2.1 ^ 6 = %f\n", f);
return 0;
and I compiled it as:
<prompt>%</prompt> <userinput>cc temp.c -lm</userinput>
like you said I should, but I get this when I run it:
<prompt>%</prompt> <userinput>./a.out</userinput>
2.1 ^ 6 = 1023.000000
This is <emphasis>not</emphasis> the right answer! What is going on?
When the compiler sees you call a function, it checks if it has already seen a prototype for it. If it has not, it assumes the function returns an <type>int</type>, which is definitely not what you want here.
So how do I fix this?
The prototypes for the mathematical functions are in <filename>math.h</filename>. If you include this file, the compiler will be able to find the prototype and it will stop doing strange things to your calculation!
#include &lt;math.h&gt;
#include &lt;stdio.h&gt;

int main() {
After recompiling it as you did before, run it:
<prompt>%</prompt> <userinput>./a.out</userinput>
2.1 ^ 6 = 85.766121
If you are using any of the mathematical functions, <emphasis>always</emphasis> include <filename>math.h</filename> and remember to link in the math library.
I compiled a file called <filename>foobar.c</filename> and I cannot find an executable called <filename>foobar</filename>. Where has it gone?
Remember, <command>cc</command> will call the executable <filename>a.out</filename> unless you tell it differently. Use the <option>-o <replaceable>filename</replaceable></option> option:
<prompt>%</prompt> <userinput>cc -o foobar foobar.c</userinput>
OK, I have an executable called <filename>foobar</filename>, I can see it when I run <command>ls</command>, but when I type in <command>foobar</command> at the command prompt it tells me there is no such file. Why can it not find it?
Unlike <trademark class="registered">MS-DOS</trademark>, <trademark class="registered">UNIX</trademark> does not look in the current directory when it is trying to find out which executable you want it to run, unless you tell it to. Type <command>./foobar</command>, which means <quote>run the file called <filename>foobar</filename> in the current directory.</quote>
I called my executable <filename>test</filename>, but nothing happens when I run it. What is going on?
Most <trademark class="registered">UNIX</trademark> systems have a program called <command>test</command> in <filename>/usr/bin</filename> and the shell is picking that one up before it gets to checking the current directory. Either type:
<prompt>%</prompt> <userinput>./test</userinput>
or choose a better name for your program!
I compiled my program and it seemed to run all right at first, then there was an error and it said something about <errorname>core dumped</errorname>. What does that mean?
The name <firstterm>core dump</firstterm> dates back to the very early days of <trademark class="registered">UNIX</trademark>, when the machines used core memory for storing data. Basically, if the program failed under certain conditions, the system would write the contents of core memory to disk in a file called <filename>core</filename>, which the programmer could then pore over to find out what went wrong.
Fascinating stuff, but what I am supposed to do now?


No matching activity found.

Browse all component changes

Things to check

Multiple failing checks

The translations in several languages have failing checks



The string uses three dots (...) instead of an ellipsis character (…)



English English
No related strings found in the glossary.

Source information

Source string comment
(itstool) path: informalexample/programlisting
no-wrap, read-only
Source string location
String age
a year ago
Source string age
a year ago
Translation file
books/developers-handbook.pot, string 205