Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Before all of this, I'd first make sure you're linking correctly. It seems like compiled fine, but failed at the linking step. So first make sure you actually have <code>semaphore.h</code> and that it includes <code>sem_init(...)</code>. If you do, and my guess is that you do, check your compile command. If that is your compile command in your question, try adding <code>-lpthread</code> to your compile line to link in the posix thread library.</p> <hr> <p>So you should double check that sema does what you want, since they're different libraries -- <code>sem</code> is from the POSIX <code>pthreads</code> library and <code>sema</code> is from the solaris <code>thread</code> library. (<a href="http://www.cs.cf.ac.uk/Dave/C/node29.html" rel="nofollow">See this also</a>) But if they're code compatible, and if you're looking for cross-platform compatible code, you'd probably want to do something like create simple wrapper functions and then conditionally include it.</p> <p>Your wrapper functions would be really simple, accept the same types and return the same type, e.g.</p> <pre><code>ret_type sem_init(argtype arg1, argtype arg2, argtype arg3) { return sema_init(arg1, arg2, arg3) } </code></pre> <p>And then conditionally include it with something like</p> <pre><code>#ifdef SOLARIS #include semaphore_wrappers.h #endif </code></pre> <p>Note that SOLARIS isn't going to be defined. You'll either have to manually <code>#define SOLARIS</code> when compiling on solaris, or define it in your compile command line / makefile.</p> <p>At least thats how I'd do it.</p> <p>Note that if this is <strong><em>not</em></strong> to be cross-platform compatible, it's much easier to read and debug if you just do a global search and replace.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload