title: C plugin system: dlopen fails
body: <p>as a continuation to this post <a href="https://stackoverflow.com/questions/36797376/c-pluginsystem-symbol-lookup-error?noredirect=1#comment61173064_36797376">C pluginsystem: symbol lookup error</a>, I am still writing my plugin system and encounter new bugs.</p>
  
  <p>To recap what the plugins are, the program consists of a network application interfaced by a shell, messages has a type and therefore can be use to create applications on the network. For exemple, a possible application would be a chat or a transfert application.</p>
  
  <p>So shell commands can send message of a particular application on the network, when a message is received, if it corresponds to a particular application then an action function is executed with the message content as argument, it could be the application.</p>
  
  <p>A plugin is a shared library with an init function that register it's commands and actions. A command could just be a simple command that doesn't interact with the network, and that's why I achieved at the moment.</p>
  
  <p>The plugin system consists in modules:</p>
  
  <ol>
  <li><em>plugin_system.c</em></li>
  <li><em>list.c</em> used by the first module to store plugins</li>
  </ol>
  
  <p>The network part consists in:</p>
  
  <ol>
  <li><em>protocol.c</em> main part of the protocol</li>
  <li><em>message.c</em> main part for message treatment</li>
  <li><em>application.c</em> main part used to program applications</li>
  <li><em>common.c</em> file with ccommon functions</li>
  <li><em>network.c</em> useful network functions</li>
  </ol>
  
  <p>The modules in protocole are all interdependent, I have split files for conveniency.
  All modules are compiled with -fPIC option.</p>
  
  <p>To compile a plugin called <em>plug.c</em> wich doesn't interact with the network, I use:</p>
  
  <pre><code>gcc -Wall -O2 -std=gnu99  -D DEBUG -g -fPIC -c -o plug.o plug.c
  gcc -Wall -O2 -std=gnu99  -D DEBUG -g -o plug.so plug.o plugin_system.o list.o -shared
  </code></pre>
  
  <p>And it works perfectly, the library is loaded with <code>dlopen</code> with no problem, the init function loaded with <code>dlsym</code> and executed correctly so the plugin is registered, I then executed the command and I can see that it work.</p>
  
  <p>Now I wan't to add supports for network communications for the plugins, so I have modified the same test plugin that I used which has just a command to print a message. I have had a call to <code>sendappmessage_all</code> a function that send a message to everyone over the network, defined in <em>message.c</em>.</p>
  
  <p>I can compile the new plugin without adding the network module objects, it compile, the plugin loads correctly, but when it call <code>sendappmessage_all</code> obviously it fails with the message </p>
  
  <pre><code> symbol lookup error: ./plugins/zyva.so: undefined symbol: sendappmessage_all
  </code></pre>
  
  <p>So to make it work, I should like the plugin with network modules so that's what I have done with</p>
  
  <pre><code>gcc -Wall -O2 -std=gnu99  -D DEBUG -g -o plug.so plug.o plugin_system.o list.o protocol.o message.o thread.o common.o application.o network.o -shared
  </code></pre>
  
  <p>It compile but when I try to load the plugin, <code>dlopen</code> return <code>NULL</code>.
  I have also tried to add just one module, at worst it would only result in an <code>undefined symbol</code> error, but I <code>dlopen</code> still return <code>NULL</code>.</p>
  
  <p>I know it's a lot of informations and on the otherside you probably wan't to see the code but I tried to be the clearer in the most succint way I could be because is way more complex and bigger than the post.</p>
  
  <p>Thank you for your understanding.</p>