test_as_needed_so.cpp:<div><br><div><div>#include <cstring></div><div>#include <cstdio></div><div><br></div><div>class Foo</div><div>{</div><div>public:</div><div>  Foo()</div><div>  {</div><div>    printf("foo init\n");</div>

<div>  }</div><div><br></div><div>  ~Foo()</div><div>  {</div><div>    printf("foo deinit\n");</div><div>  }</div><div>};</div><div><br></div><div>Foo foo;</div><div><br></div><div>test_as_needed.cpp</div><div>
#include <cstdio></div>
<div><br></div><div>int main(int argc, char** argv) </div><div>{</div><div>  printf("main\n");</div><div>}</div><div><br></div><div><br></div><div><div><div><br></div></div></div><div><div>jfaust@bvu:~/scratch$ g++ test_as_needed_so.cpp -shared -fPIC -o libtest_as_needed_so.so</div>

<div>jfaust@bvu:~/scratch$ g++ test_as_needed.cpp -o test_as_needed -ltest_as_needed_so</div><div>jfaust@bvu:~/scratch$ ./test_as_needed</div><div>foo init</div><div>main</div><div>foo deinit</div></div><div><br></div><div>

<div>jfaust@bvu:~/scratch$ g++ test_as_needed.cpp -Wl,--as-needed -o test_as_needed -ltest_as_needed_so</div><div>jfaust@bvu:~/scratch$ ./test_as_needed</div><div>main</div></div><div><br></div><div><br></div><div>If you use the variable it has to link it in... it's when there's some global initialization that causes side effects even if you're not explicitly referencing any symbols.  Not necessarily a problem, but something to look out for.</div>

<div><br></div><div>Josh</div><br><div class="gmail_quote">On Thu, Aug 12, 2010 at 4:13 PM, Daniel Stonier <span dir="ltr"><<a href="mailto:d.stonier@gmail.com">d.stonier@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br><br><div class="gmail_quote"><div><div></div><div class="h5">On 10 August 2010 02:32, Josh Faust <span dir="ltr"><<a href="mailto:jfaust@willowgarage.com" target="_blank">jfaust@willowgarage.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br>
</div>Happy to hear that it works in general (would be pretty bad if it<br>
didn't...).  I'm more concerned about whether we're currently<br>
specifying everything completely, or unknowingly exploiting<br>
overlinkage.<br>
<br>
I guess the only way to find out is to build and test everything with<br>
that option included.<br><font color="#888888"><br></font></blockquote><div><br></div></div><div>I just did two quick tests:</div><div> 1) .so that overrides a global symbol (strstr in this case)</div>

<div> 2) .so with a global object that has a constructor/destructor</div><div><br></div><div>#1 worked, #2 failed (the .so was removed).</div><div><br></div><div>If #1 failed I'd say we can't default to it.  Not sure how important #2 is, but it's something that could definitely cause problems that would be difficult to track down.</div>




<div><br></div><font color="#888888"><div>Josh </div></font></div></blockquote><div><br></div></div></div><div>Josh, how did you produce result 2)? I just tested it here to be aware of when it might break and couldn't reproduce the failure. It correctly excludes/includes the library when I comment/uncomment the relevant usage of the variable. Snippets below:</div>


<div><br></div><div>LIBRARY HPP:</div><div><br></div><div>namespace ecl {<br><br>class A {<br>public:<br> A() : i(3) {}<br> ~A() {}<br>       int i;<br>};<br>extern const A a;<br><br>}<br></div><div><br></div><div>LIBRARY CPP:</div>


<div><br></div><div>namespace ecl {<br></div><div><br></div><div>const A a;</div><div><br></div><div>}</div><div><br></div><div>MAIN CPP</div><div><br></div><div>int main() {<br></div><div>    std::cout << "i: " << ecl::a.i << std::endl;</div>


<div>    return 0;</div><div>}</div><div><br></div><div><br></div><div><br></div><div><br></div></div><br clear="all"><br>-- <br><div><div></div><div class="h5">Phone : +82-10-5400-3296 (010-5400-3296)<br>Home: <a href="http://snorriheim.dnsdojo.com/" target="_blank">http://snorriheim.dnsdojo.com/</a><br>


Yujin Robot: <a href="http://www.yujinrobot.com/" target="_blank">http://www.yujinrobot.com/</a><br>Embedded Control Libraries: <a href="http://snorriheim.dnsdojo.com/redmine/wiki/ecl" target="_blank">http://snorriheim.dnsdojo.com/redmine/wiki/ecl</a><br>



</div></div><br>_______________________________________________<br>
ros-users mailing list<br>
<a href="mailto:ros-users@code.ros.org">ros-users@code.ros.org</a><br>
<a href="https://code.ros.org/mailman/listinfo/ros-users" target="_blank">https://code.ros.org/mailman/listinfo/ros-users</a><br>
<br></blockquote></div><br></div></div>