<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>[RESOLVED] Error when using library</title>
<description> Hi everybody,

i&amp;#039;ve code a quite large framework and it works very well. So i&amp;#039;ve decided to put it in a static library (.a) using that:


#---------------------------------------------------------------------------------
%.a:
@echo linking to lib ... $(notdir $@)
@$(AR) -rc $@ $^

# and i&amp;#039;ve changed the output with this
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).a: $(OFILES)

My library is well created (no errors or warning). I&amp;#039;ve recoded my application replacing all my framework source files by the library. It compile without any errors but it fails at runtime.
I haven&amp;#039;t change any code in the source code except i&amp;#039;ve made a mylib.h wich include all elements of all my framework headers (i haven&amp;#039;t put all method/function in mylib.h, because some are private methods and other are for a internal used).

Is someone has an idea about the origin of the bug? If i use the --whole-archive linker option will change something?
I&amp;#039;m lost :) I don&amp;#039;t understand at all where this bug can come from.......</description><link>http://forum.wiibrew.org/read.php?11,37933,37933#msg-37933</link><lastBuildDate>Tue, 16 Jun 2026 12:00:17 +0200</lastBuildDate>
<generator>Phorum 5.2.23</generator>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,38339#msg-38339</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,38339#msg-38339</link><description><![CDATA[ Yes, you can expect trouble if you use a different class definition like that.]]></description>
<dc:creator>henke37</dc:creator>
<category>Coding</category><pubDate>Sun, 18 Oct 2009 00:25:32 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,38155#msg-38155</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,38155#msg-38155</link><description><![CDATA[ Hi all, i&#039;ve fixed the problem. I don&#039;t know if i have the good explanation but i willput it here :)<br /><br />I imagine that i&#039;ve a lot of classes (some are very simple and other aren&#039;t. For exemple, i use functor, the singleton pattern etc...). So, i&#039;ve some private fields. All is compiling very well.<br /><br />Then i create a library "libitems.a". I wan&#039;t to publish a libitems.h file wich will describe all my items. But this header won&#039;t contains all the field/methods of my classes (for exemple, i hide private elements). It won&#039;t succed at the runtime.<br />But if i put all elements in the header, it will run without any problem.<br /><br />So, i think that when i compile my sources into a library, for:<br /><br /><pre class="bbcode">
class A
{
private:
  int test;
public:
  void Do();
}</pre><br />The object in the library will only be registered under the class name. So the Do methods will be stored at the A object location plus an offset of 4 bytes (the length of hte private int field).<br /><br />Then, if in my project i use the libitem.h like that:<br /><br /><pre class="bbcode">
class A
{
public:
  void Do();
}</pre><br />and that code:<br /><br /><pre class="bbcode">
int main()
{
  A a;
  a.Do();
}</pre><br />The compiler will create an object (fior the main function) and will put a link (for the line a.Do()) to the A object at the offset 0 (because in my libutils.h, i&#039;ve not the int field).<br />Then the linker will try to find the A object (it will succed) and link to the offset 0 and this will create an error at the runtime because my method is at the offset 4. To add, it won&#039;t create an error at the compilation, because the linker only search the location of the A object, not the inner methods....<br /><br />If i add the private int field into the libutils.h, all will run without any problem.<br /><br />So here is my explanation. I don&#039;t know if these is the good explanation, but it can explain my problem.]]></description>
<dc:creator>arasium</dc:creator>
<category>Coding</category><pubDate>Fri, 16 Oct 2009 11:10:01 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,38077#msg-38077</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,38077#msg-38077</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>arasium</strong><br />it&#039;s a runtime error.</div></blockquote>
In that case, you need to show us your library and it&#039;s entire source or fix the problem yourself.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Thu, 15 Oct 2009 16:55:10 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,38073#msg-38073</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,38073#msg-38073</link><description><![CDATA[ Are you mixing C and C++ code?]]></description>
<dc:creator>Daid</dc:creator>
<category>Coding</category><pubDate>Thu, 15 Oct 2009 16:12:16 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,38065#msg-38065</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,38065#msg-38065</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>Arikado</strong><br /><blockquote class="bbcode"><div><small>Quote<br /></small><strong>arasium</strong><br /><blockquote class="bbcode"><div><small>Quote<br /></small><strong>Arikado</strong><br />Sounds like you&#039;re not properly linking your library into projects that use it.</div></blockquote><br />Yes, i was thinking about something like that. For the linker, i use the default devkitpro options. Should i add an other one?</div></blockquote>
Just several quick pointers:<br />1) Make sure that your lib is named <b>lib</b>whatever.a - You must have the first three characters named lib for it to be recogonized by devkitPPC compile<br /><br />2) Make sure that your library is stored in the correct libs directory with the rest of your devkitPPC libraries (c:/devkitPRO/devkitPPC/libs -- Or something like that is the proper path)<br /><br />3) In your makefile for your project using your library, link it in under LIBS: using "-l" in place of "lib" EX:<br />-lsomething<br /><br />4) In your project&#039;s C/C++ files using your lib, make sure you properly #include it.<br /><br />Good luck!!!</div></blockquote><br />:) All of these points will lead to a compilation error. I haven&#039;t any compilation error, it&#039;s a runtime error.]]></description>
<dc:creator>arasium</dc:creator>
<category>Coding</category><pubDate>Thu, 15 Oct 2009 10:20:33 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,37956#msg-37956</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,37956#msg-37956</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>arasium</strong><br /><blockquote class="bbcode"><div><small>Quote<br /></small><strong>Arikado</strong><br />Sounds like you&#039;re not properly linking your library into projects that use it.</div></blockquote><br />Yes, i was thinking about something like that. For the linker, i use the default devkitpro options. Should i add an other one?</div></blockquote>
Just several quick pointers:<br />1) Make sure that your lib is named <b>lib</b>whatever.a - You must have the first three characters named lib for it to be recogonized by devkitPPC compile<br /><br />2) Make sure that your library is stored in the correct libs directory with the rest of your devkitPPC libraries (c:/devkitPRO/devkitPPC/libs -- Or something like that is the proper path)<br /><br />3) In your makefile for your project using your library, link it in under LIBS: using "-l" in place of "lib" EX:<br />-lsomething<br /><br />4) In your project&#039;s C/C++ files using your lib, make sure you properly #include it.<br /><br />Good luck!!!]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Wed, 14 Oct 2009 18:21:49 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,37948#msg-37948</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,37948#msg-37948</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>Arikado</strong><br />Sounds like you&#039;re not properly linking your library into projects that use it.</div></blockquote><br />Yes, i was thinking about something like that. For the linker, i use the default devkitpro options. Should i add an other one?<br /><br /><blockquote class="bbcode"><div><small>Quote<br /></small><strong>Arikado</strong><br />Sounds like you&#039;re not properly linking your library into projects that use it.</div></blockquote>
It depends :) Sometime many instance of a class are not well instanciated (instead, all instance are one. for exemple, if i create three counter, all counter will be at the same memory space....). Other time, the stack is corrupted or my object attribute values randomly change ?!!! So, i can say that it&#039;s a random effect.<br /><br />I can&#039;t publish my code for the moment (i want to clean it, add comments etc....). So if you absolutely need it to help me, i will try to put the comments as soon as possible.]]></description>
<dc:creator>arasium</dc:creator>
<category>Coding</category><pubDate>Wed, 14 Oct 2009 17:32:09 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,37939#msg-37939</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,37939#msg-37939</link><description><![CDATA[ Sounds like you&#039;re not properly linking your library into projects that use it.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Wed, 14 Oct 2009 17:03:51 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,37935#msg-37935</guid>
<title>Re: Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,37935#msg-37935</link><description><![CDATA[ What was the problem again?]]></description>
<dc:creator>henke37</dc:creator>
<category>Coding</category><pubDate>Wed, 14 Oct 2009 15:26:15 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,37933,37933#msg-37933</guid>
<title>[RESOLVED] Error when using library</title><link>http://forum.wiibrew.org/read.php?11,37933,37933#msg-37933</link><description><![CDATA[ Hi everybody,<br /><br />i&#039;ve code a quite large framework and it works very well. So i&#039;ve decided to put it in a static library (.a) using that:<br /><br /><pre class="bbcode">
#---------------------------------------------------------------------------------
%.a:
	@echo linking to lib ... $(notdir $@)
	@$(AR) -rc $@ $^

# and i&#039;ve changed the output with this
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).a: $(OFILES)</pre><br />My library is well created (no errors or warning). I&#039;ve recoded my application replacing all my framework source files by the library. It compile without any errors but it fails at runtime.<br />I haven&#039;t change any code in the source code except i&#039;ve made a mylib.h wich include all elements of all my framework headers (i haven&#039;t put all method/function in mylib.h, because some are private methods and other are for a internal used).<br /><br />Is someone has an idea about the origin of the bug? If i use the --whole-archive linker option will change something?<br />I&#039;m lost :) I don&#039;t understand at all where this bug can come from.......]]></description>
<dc:creator>arasium</dc:creator>
<category>Coding</category><pubDate>Wed, 14 Oct 2009 12:02:38 +0200</pubDate></item>
</channel>
</rss>