title: `Cannot find -lmalloc`, error: ld returned 1 exit status
body: <p>Currently trying to compile this program using
  <code>g++ -o crack crack2.c -lcrypt -lpthread -lmalloc</code> and am getting:</p>
  
  <p><code>z@ubuntu:~/Desktop$ g++ -o crack crack2.c -lcrypt -lpthread -lmalloc</code></p>
  
  <p><code>/usr/bin/ld: cannot find -lmalloc</code></p>
  
  <p><code>collect2: error: ld returned 1 exit status</code></p>
  
  <p>So.. If I remove the <code>-lmalloc</code>, I get <code>undefined reference to 'passwordLooper(void*)'</code>.</p>
  
  <p>Really unsure of how to fix this problem. It has to be something related to malloc or -lmalloc because before I worked in the malloc(), everything worked as intended and the program compiled.</p>
  
  <pre><code>/*
  crack.exe
  */
  /*  g++ -o crack crack.c -lcrypt -lpthread -lmalloc */
  //define _GNU_SOURCE
  #include &lt;malloc.h&gt;
  
  #include &lt;crypt.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;string.h&gt;
  #include &lt;math.h&gt;
  
  
  
  void *passwordLooper(void *passwordData);
  //void *threadFunction(void *threads);
  typedef struct{
      int keysize;
      char *target;
      char *salt;
  }passwordData;
  
  int main(int argc, char *argv[]){           /* usage = crack threads keysize target */
      int i = 0;
      /*  arg[0] = crack, arg[1] = #of threads arg[2] = size of password, arg[3] = hashed password being cracked */
  
      if (argc !=  4) {
          fprintf(stderr, "Too few/many arguements give.\n");
          fprintf(stderr, "Proper usage: ./crack threads keysize target\n");
          exit(0);
      }
  
      int threads = *argv[1]-'0';         // threads is now equal to the second command line argument number
      int keysize = *argv[2]-'0';         // keysize is now equal to the third command line argument number
      char target[9]; 
      strcpy(target, argv[3]);
      char salt[10];
  
      while ( i &lt; 2 ){            //Takes first two characters of the hashed password and assigns them to the salt variable
          salt[i] = target[i];
          i++;
      }
  
  
      printf("threads = %d\n", threads);      /*used for testing */
      printf("keysize = %d\n", keysize);
      printf("target = %s\n", target);        
      printf("salt = %s\n", salt);        
  
  
      if (threads &lt; 1 || threads &gt; 8){
          fprintf(stderr, "0 &lt; threads &lt;= 8\n");
          exit(0);
      }                                               /*Checks to be sure that threads and keysize are*/
      if (keysize &lt; 1 || keysize &gt; 8){                                                /*of the correct size   */
          fprintf(stderr, "0 &lt; keysize &lt;= 8\n");
          exit(0);
      }
  
      pthread_t t1,t2,t3,t4,t5,t6,t7,t8;
  
      struct crypt_data data;
      data.initialized = 0;
      //~ passwordData.keysize = keysize;
      //~ passwordData.target = target;
      //~ passwordData.salt = salt;
  
      passwordData *pwd = (passwordData *) malloc(sizeof(pwd));
      pwd-&gt;keysize = keysize;
      pwd-&gt;target = target;
      pwd-&gt;salt = salt;
  
  
      //~ if ( threads = 1 ){
          //~ pthread_create(&amp;t1, NULL, *threadFunction, threads);
      //~ }
  
  
      char unSalted[30];
      int j = 0;
      for (i = 2; target[i] != '\0'; i++){        /*generates variable from target that does not include salt*/
          unSalted[j] = target[i];
          j++;
      }
      printf("unSalted = %s\n", unSalted); //unSalted is the variable target without the first two characters (the salt)
  
      char password[9] = {0};
      passwordLooper(pwd);
  
  
  }
  
  
  
  
  /*_____________________________________________________________________________________________________________*/
  /*_____________________________________________________________________________________________________________*/
  void *passwordLooper(passwordData *pwd){
      char password[9] = {0};
      int result;
  
      int ks = pwd-&gt;keysize;
      char *target = pwd-&gt;target;
      char *s = pwd-&gt;salt;
  
      for (;;){
          int level = 0; 
          while (level &lt; ks &amp;&amp; strcmp( crypt(password, s), target ) != 0) {
              if (password[level] == 0){
                  password[level] = 'a';
                  break;
              }
              if (password[level] &gt;= 'a' &amp;&amp; password[level] &lt; 'z'){
                  password[level]++;
                  break;
              }
              if (password[level] == 'z'){
                  password[level] = 'a';
                  level++;
              }
          }
  
          char *cryptPW = crypt(password, s);
          result = strcmp(cryptPW, target);
  
          if (result == 0){               //if result is zero, cryptPW and target are the same
              printf("result = %d\n", result);
              printf ("Password found: %s\n", password);
              printf("Hashed version of password is %s\n", cryptPW);
              break;  
          }
          if (level &gt;= ks){           //if level ends up bigger than the keysize, break, no longer checking for passwords
              printf("Password not found\n");
              break;
          }
      }
      exit(0);
  }
  </code></pre>