Fighting with lib linking

SGDK only sub forum

Moderator: Stef

Post Reply
KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Fighting with lib linking

Post by KanedaFr » Wed Jun 18, 2014 7:44 pm

Hi there,

I hope you'll be able to help me on this one again because it's making me crazy !

So, I have a lib and a game

Lib calls severals function of SGDK
game call severals function of Lib and SGDK

Let's say Lib call
- VDP_setHorizontalScroll() from vdp_bg.c/.h, into a scroll function
- VDP_setVerticalScroll() from vdp_bg.c/.h, into a scroll function
- JOY_init() from joy.c, into a joy_start() function

Let's say game call
- JOY_init() from joy.c/.h
- Joy_start() from lib
- scroll() from lin

My problem ?
Joy_start() perfectly works
scroll() produce a "undefined reference to VDP_setHorizontalScroll()/VDP_setVerticalScroll()"

From what I understood, for scroll() to work, I must make reference somewhere (in my game) to vdp_bg.c/.h to game link to sgdk.vdp_bg and lib could so use sgdk.vdp_bg function.


I'm very poor on linking and library stuff so does someone could help me to find the right way to compile Lib.a or/and to link Link.a without undefined reference errors ?

thanks a lot !

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Wed Jun 18, 2014 8:17 pm

:oops: :oops: :oops: :oops: :oops:

Correct answer : Order matters with libraries

:oops: :oops: :oops: :oops: :oops:

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Jun 19, 2014 3:04 am

Gcc tries to minimize the code copied from objects/libraries by only linking in functions that have been used at the time the object/library is linked. So if an object/library is linked before an object/library that uses the object/library, the used functions will not have been copied and give errors. Always link objects/libraries after objects/libraries that use said objects/libraries. In a few rare cases, you might have to have a library in the link list twice - both before and after another object/library.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Thu Jun 19, 2014 9:06 pm

Thanks for this ;)
In a few rare cases, you might have to have a library in the link list twice - both before and after another object/library.
:shock: Crazy!

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu Jun 19, 2014 10:15 pm

KanedaFr wrote:Thanks for this ;)
In a few rare cases, you might have to have a library in the link list twice - both before and after another object/library.
:shock: Crazy!
Very. I ran into that a few times on the PSP in particular. Something about some of the libraries on that meant you needed them linked in twice.

Post Reply