Tuesday, October 26, 2010

LaTeX: MiKTeX undefined references

For the past three days I tried to get started with LaTeX on Windows. Using MiKTeX, I ended up in a situation where (a) my bibliography wasn't showing at all, (b) citations showed up as [?], and (c) the log complained about undefined references.

It turned out that the errors were obscure and unrelated to the cause. The references and citations were fine; it was the bibliography style that was incorrect. It needs to be like this to work:

\bibliographystyle{plain}
\bibliography{mybib}
\nocite{*}

You need to use \bibliographystyle and not \bibstyle that appears on some websites. The style needs to exist or it will not work. The bibliography file specified must be without the .bib extension. \nocite{*} is optional and makes LaTeX include references even if they are not cited.

Also, you may need to compile two or three times for the references to be properly linked.

Saturday, October 16, 2010

inet_ntoa() segmentation fault issue

inet_ntoa is a UNIX system call used in socket programming to obtain an IPv4 string form of an IP address from its in_addr form.

I have encountered an issue where its use results in the following warning:

warning: assignment makes pointer from integer without a cast

Attempting to run a program with this warning on inet_ntoa will result in a segmentation fault.

The cause of the problem is not incorrect C, but a missing header file. Shachar Shemesh wrote that the solution to this obscure problem is simply to include the arpa/inet.h header file:

#include <arpa/inet.h>