title: Application can not find OpenSSL used to compile library
body: <p>I have an application that uses the JNI to call a C file that reads some system information.  I have this running fine on Linux, but on Solaris 10 (SPARC, 32-bit) I am having trouble when the library is used.  I compiled the C file on the same machine that I am testing it on with the command:</p>
  
  <pre><code>gcc -O2 -fPIC -shared -static-libgcc -I/usr/local/ssl/include \
      -I$JAVA_HOME/include -I$JAVA_HOME/include/solaris -lcrypto \
      -lm -std=c99 -o libosaccess.so osaccess.c
  </code></pre>
  
  <p>This compiles fine, but unlike on Linux, I had to include the path to the system OpenSSL, <code>-I/usr/local/ssl/include</code>.  This is obviously the problem, as when the library is used, I get the following fatal error due to an OpenSSL type:</p>
  
  <pre><code>ld.so.1: java: fatal: relocation error: file /workspace/solaris_sparc/libosaccess.so: symbol EVP_aes_256_cbc: referenced symbol not found
  Killed
  </code></pre>
  
  <p>I have tried adding the location of the system OpenSSL to the <code>PATH</code> and also my <code>LD_LIBRARY_PATH</code>, but continue to get the error.  I have read that I can see the paths that my application is looking using <code>ldd -d</code> but can't quite seem to get this working as of yet.</p>
  
  <p>Can anyone tell me if there is a way I can set where the OpenSSL files are so that all applications can find them?  On my Linux machine, there are no environment variables that include the path to the OpenSSL on that.  There is, however, a binary called <code>openssl</code> under <code>/usr/bin</code>, which is included in the <code>PATH</code> variable.  I have found a binary on Solaris, but adding this to the <code>PATH</code> doesn't help.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>@ nudzo and Kenster</p>
  
  <p>Ok so rather than try to squeeze this into the comments box for your answers, I thought I'd post it in addition to my question to improve the readability.</p>
  
  <p>So I have checked my system and there is only the two copies of OpenSSL that I can find.</p>
  
  <ul>
  <li>Doing a <code>pkginfo | grep 'SUNWcry*'</code> shows that I have the two additional packages installed.</li>
  <li>Only the <code>/usr/sfw</code> location has the two 'extra' libraries you mentioned</li>
  <li>Both locations have the <code>evp.h</code> header file that includes the <code>EVP_aes_256_cbc</code> symbol.</li>
  </ul>
  
  <p>The locations are:</p>
  
  <p><strong>/usr/sfw</strong></p>
  
  <pre><code>xxx-1035&gt; find /usr/sfw -type f -name 'openssl'
   /usr/sfw/bin/openssl
  xxx-1036&gt; find /usr/sfw -type f -name 'evp.h'
   /usr/sfw/include/openssl/evp.h
  xxx-1037&gt; find /usr/sfw -type f -name 'libcrypto*'
   /usr/sfw/lib/sparcv9/libcrypto.so.0.9.7
   /usr/sfw/lib/sparcv9/libcrypto_extra.so.0.9.7
   /usr/sfw/lib/libcrypto.so.0.9.7
   /usr/sfw/lib/libcrypto_extra.so.0.9.7
  xxx-1038&gt; find /usr/sfw -type f -name 'libssl*'
   /usr/sfw/lib/sparcv9/libssl.so.0.9.7
   /usr/sfw/lib/sparcv9/libssl_extra.so.0.9.7
   /usr/sfw/lib/libssl.so.0.9.7
   /usr/sfw/lib/libssl_extra.so.0.9.7
  </code></pre>
  
  <p><strong>/usr/local/ssl</strong></p>
  
  <pre><code>xxx-1040&gt; find /usr/local/ssl -type f -name 'openssl'
   /usr/local/ssl/bin/openssl
  xxx-1041&gt; find /usr/local/ssl -type f -name 'evp.h'
   /usr/local/ssl/include/openssl/evp.h
  xxx-1042&gt; find /usr/local/ssl -type f -name 'libcrypto*'
   /usr/local/ssl/lib/libcrypto.a
   /usr/local/ssl/lib/libcrypto.so.0.9.7
   /usr/local/ssl/lib/libcrypto.so.0.9.8
   /usr/local/ssl/lib/pkgconfig/libcrypto.pc
  xxx-1043&gt; find /usr/local/ssl -type f -name 'libssl*'
   /usr/local/ssl/lib/libssl.a
   /usr/local/ssl/lib/libssl.so.0.9.7
   /usr/local/ssl/lib/libssl.so.0.9.8
   /usr/local/ssl/lib/pkgconfig/libssl.pc
  </code></pre>
  
  <p>I recompiled my C file using:</p>
  
  <pre><code>gcc -O2 -fPIC -shared -static-libgcc \
      -I$JAVA_HOME/include -I$JAVA_HOME/include/solaris \
      -I/usr/sfw/include -L/usr/sfw/lib -R/usr/sfw/lib \
      -lcrypto -lm -std=c99 -o libosaccess.so osaccess.c
  </code></pre>
  
  <p>Again, omission of the path to the headers throws <code>implicit declaration of function</code> errors of the EVP types when compiling.  This, however, still causes the same error as originally posted.</p>
  
  <p>So if there are only these two copies on the system, that would indicate that instead of using the version shipped with Solaris (<code>/usr/sfw</code>), the system default is using the <code>/usr/local</code> copy that doesn't have the additional 'extra' shared objects.  Would that be a fair assumption to make?  How would I conclusively check this?  I don't have permissions to remove either copy.</p>
  
  <p>Also, running <code>cryptoadm list -mv</code> output a lot of information I didn't quite understand.  However I found these entries in a couple of the slot tables:</p>
  
  <pre><code>CKM_AES_CBC                  16   32   .  X  X  .  .  .  .  .  .  .  X  X  .  .
  </code></pre>
  
  <p>and also:</p>
  
  <pre><code>Kernel software providers:
  ==========================
  aes256: CKM_AES_ECB,CKM_AES_CBC,CKM_AES_CTR
  
  Kernel hardware providers:
  ==========================
  n2cp/0: CKM_DES_CBC,...,CKM_AES_CBC,...
  </code></pre>
  
  <p>I apologise for the huge amount of extra information.</p>