title: Cannot compile program on Ubuntu that uses libmcrypt
body: <p>I created a C program that uses <em>libmcrypt</em>. I compiled it for many times in a CentOS machine, but now, trying to do the same thing in Ubuntu, I get this:</p>
  <pre><code>/tmp/ccM2ugbq.o: In function `encrypt': 
  util.c:(.text+0xa1): undefined reference to `mcrypt_module_open'
  util.c:(.text+0xc6): undefined reference to `mcrypt_enc_get_iv_size'
  util.c:(.text+0x134): undefined reference to `mcrypt_generic_init'
  util.c:(.text+0x1dc): undefined reference to `mcrypt_generic'
  util.c:(.text+0x1fa): undefined reference to `mcrypt_module_close'
  /tmp/ccM2ugbq.o: In function `decrypt':
  util.c:(.text+0x288): undefined reference to `mcrypt_module_open'
  util.c:(.text+0x296): undefined reference to `mcrypt_enc_get_iv_size'
  util.c:(.text+0x304): undefined reference to `mcrypt_generic_init'
  util.c:(.text+0x375): undefined reference to `mdecrypt_generic'
  util.c:(.text+0x380): undefined reference to `mcrypt_module_close'
  </code></pre>
  <p>, although I have installed <em>libmcrypt</em> and have spacified the flags properly when compile (<em>-I/usr/include -L/usr/lib -lmcrypt</em>)</p>
  <p>Can anyone guide me on how to get the compilation work  properly with <em>libmcrypt</em>?</p>
  <hr />
  <p>EDIT: man pages says: <em>Compile as &quot;cc prog.c -lmcrypt&quot;, or &quot;cc prog.c -lmcrypt -lltdl&quot; depending on your  installation.</em>
  I also installed <em>libltdl-dev</em>, but it does not work.</p>
  <hr />
  <p>EDIT 1:
  System information:
  version (running <code>uname -r</code>):</p>
  <blockquote>
  <p>3.5.0-25-generic</p>
  </blockquote>
  <p>release (running <code>lsb_release -a</code>):</p>
  <blockquote>
  <p>No LSB modules are available.</p>
  <p>Distributor ID:   Ubuntu</p>
  <p>Description:  Ubuntu 12.10</p>
  <p>Release:  12.10</p>
  <p>Codename: quantal</p>
  </blockquote>
  <hr />
  <p>EDIT 2:</p>
  <p>Because @teppic requested me to show the compile command, I solved my issue, but I need some explanations. Bellow I'll detail the topic:</p>
  <p>the command that I used and failed:</p>
  <blockquote>
  <p>cc -Wall -I../path/to/include -lmcrypt ./a_file.c ./some/other/file.c ./some/other/files.c ./main/file.c  -I/some/include/path -lother_lib -o ./bin/out</p>
  </blockquote>
  <p>After that, I only put the <code>-lmcrypt</code> at the end of command and deleted it from the first place, and it worked.
  In my initial question, I told you that I did compile it before in CentOS and everything worked fine. That's true, even if in CentOS the compile command were the former one (probably some files differ in order or some libraries).</p>
  <p>Can anybody explain me how the flags order influences the compilation success or failure?</p>