title: How to link to shared lib in c++
body: <p>Could someone help me with linking to a shared lib, specifically libzmq, in C++?  </p>
  
  <pre><code>all: clean compile                                        
  
  clean:                                                    
      rm bin *.o -f                                         
  
  compile:                                                  
      g++ -g -Wall -I/usr/local/include -L/usr/local/lib main.cpp -lzmq -o bin
  </code></pre>
  
  <p>I've installed libzmq using the following steps: </p>
  
  <pre><code>git clone https://github.com/zeromq/libzmq.git
  cd libzmq
  ./autogen.sh
  ./configure
  make &amp;&amp; sudo make install
  </code></pre>
  
  <p>Here's my main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;                                                       
  #include &lt;string&gt;                                                         
  
  #include &lt;zmq/zmq.h&gt;                                                    
  
  // Required by fork routine                                               
  #include &lt;sys/types.h&gt;                                                    
  #include &lt;unistd.h&gt;                                                       
  
  // Required by wait routine                                               
  #include &lt;sys/wait.h&gt;                                                     
  
  #include &lt;stdlib.h&gt;         // Declaration for exit()                     
  #include &lt;cstdio&gt;           // printf                                     
  using namespace std;                                                      
  
  int global_variable = 2;                                                  
  
  int main(int argc, char** argv){                                          
      const short int FORK_FAILED = -1;                                     
      const short int FORK_SUCCESS = 0;                                     
      int stack_variable = 20;                                              
      pid_t pid;                                                            
      string status_identifier;                                             
      switch (pid = fork()){                                                
          case FORK_SUCCESS:                                                
              printf("Child changing global and stack variables\n");        
              global_variable++;                                            
              stack_variable++;                                             
              break;                                                        
          case FORK_FAILED:                                                 
              cerr &lt;&lt; "Failed!  -- Failed to fork:  " &lt;&lt; pid &lt;&lt; endl;       
              exit(1);                                                      
          default:                                                          
              printf("Child process (pid=%d) created successfully.\n", pid);
              wait(0);                                                      
              break;                                                        
      }                                                                     
      printf("[pid=%d] Global:  %d\n", pid, global_variable);               
      printf("[pid=%d] Stack:  %d\n", pid, stack_variable);                 
      return 0;                                                             
  }                                                                         
  </code></pre>
  
  <p>And, here's the error msg:  </p>
  
  <pre><code>bitcycle @ ubuntu64vm ~/git/test $ make
  rm bin *.o -f
  g++ -g -Wall -I/usr/local/include -L/usr/local/lib main.cpp -lzmq -o bin
  main.cpp:4:23: fatal error: zmq/zmq.hpp: No such file or directory
  compilation terminated.
  make: *** [compile] Error 1
  </code></pre>
  
  <p>The error is pretty straight forward, but I've yet to find a solution.  Any ideas?</p>
  
  <p>My goal is to do something like <a href="http://zguide.zeromq.org/cpp%3ahwclient" rel="nofollow">this</a> with multiple child processes.</p>
  
  <p><strong>Update</strong>  I'm just going to install it system-wide in ubuntu:  <code>sudo apt-get install libzmq-dev</code>, and that resolved the issue.  It doesn't teach me anything about how to identify a shared lib and header file on disk and link to it... but I guess I can move that to another day. </p>