gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > makefile and external library problems

#145992 - ecaheti - Tue Nov 27, 2007 9:39 am

Hi everyone!

Quick presentation of me and my project.
I'm a student and i'm working on a project about driving a robot (Pekee, by Wanyrobotics) with a DS.

The developpement of the interfaces are quite advanced (thanks to PAlib) but I have problems with the communication between the DS and the robot. For it I have the full linux source code of a working program (compiling with a makefile).

When I only integrate the robot library
Code:
#include "lib-pekee/libRobot/WRobotPekee.h" //inclusion des librairies du robot

no trouble happens.

But when I want to use the library, for exemple with the declaration of an object define in this
Code:
WRobotPekee pekee = WRobotPekee();   //D?claration d'un objet Pekee

I get a compilation error, maybe a link error, I don't know exactly
Code:
d:/devkitPro/PA_Pekee/Main-boutons-cible-formes-spatiale/source/main.cpp:39: undefined reference to `WRobotPekee::WRobotPekee()'
d:/devkitPro/PA_Pekee/Main-boutons-cible-formes-spatiale/source/main.cpp:183: undefined reference to `WRobotPekee::~WRobotPekee()'


Some people told me that I have to create a "static library (.a)" and integrate it into the makefile of the DS project, but I don't know how to create a static library (with devkitpro?) and how integrate it in a makefile.

here is the makefile of the DS project
http://ftpbobby.free.fr/Temp/Makefile%20ds.txt
and here is the makefile of the linux project of the robot
http://ftpbobby.free.fr/Temp/Makefile%20pekee.txt

The subject is complex, but I'm in trouble since 3 months! I can give you more details if needed.

Thank you by advance.

#145995 - PypeBros - Tue Nov 27, 2007 10:38 am

you create a static library with the "ar" tool .
e.g.
Code:

libpppds.a: arm9/build/GuiEngine.o arm9/build/Wifindows.o arm9/build/exec.o arm9/build/happyhttp.o arm9/build/selfupdate.o arm9/build/wifidgets.o
    $(AR) -r $@ $?


then you simply include the ".a" file in the list of libraries, e.g.
Code:

LIBS   := $(DSROOT)/runme/libpppds.a -lnds9 -ldswifi9 -lfat

_________________
SEDS: Sprite Edition on DS :: modplayer

#146006 - ecaheti - Tue Nov 27, 2007 5:06 pm

Is the "ar" tool able to generate code for the NDS or is it a general application?

#146007 - kusma - Tue Nov 27, 2007 5:16 pm

"ar" does not generate any code, it simply packages existing files together. AFAIK it's not concerned with what you put in the archive (it's a general tool), but devkitARM comes with an "arm-eabi-ar(.exe)" anyway that can be used for the purpose of making static libraries for the DS. Any other "ar"-tool you might have does not come from devkitARM.

#146025 - tepples - Tue Nov 27, 2007 8:48 pm

kusma wrote:
"ar" does not generate any code, it simply packages existing files together.

True; 'ar' could be used like 'tar' if you want. You generate relocatable object code files (*.o) using 'gcc -c', and then you use 'ar' to toss them into a library. However, 'ar' does understand *.o well enough to generate a symbol index for them when you use the -s flag (which has the same effect as 'ranlib').
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#146128 - ecaheti - Thu Nov 29, 2007 10:49 am

ok
I will try stuffs with ar.

few questions :
@kusma
what is "AFAIK"

@all
Is a good idea to replace every "CC" by "ar" in the makefile of the robot project?

#146129 - Lick - Thu Nov 29, 2007 11:25 am

What about:

Code:
WRobotPekee pekee;

// or

WRobotPekee *pekee = new WRobotPekee();


And also, copy the Robot's CPP file to the current project and make sure that file is being compiled.
If it's only two files, don't bother creating a static library.
_________________
http://licklick.wordpress.com

#146134 - tepples - Thu Nov 29, 2007 1:42 pm

ecaheti wrote:
few questions :
@kusma
what is "AFAIK"

The first few Google results should explain.

Quote:
@all
Is a good idea to replace every "CC" by "ar" in the makefile of the robot project?

No. You leave all the calls to $(CC) -c in there so that you get the .o files. Then you add a line that uses arm-eabi-ar to pack the desired .o files into a library.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#146139 - ecaheti - Thu Nov 29, 2007 3:49 pm

Ok I tried some stuff.

I tried to build "libpekee.a" with the makefile, but I couldn't. Here it is
Code:
libpekee.a: debug/main.o  debug/TCPClient.o  debug/WDevice.o  debug/WDriver.o  debug/WNetworkObjectTransport.o  debug/WRobot.o  debug/WRobotPekee.o  debug/WServiceDirectory.o
   $(arm-eabi-ar) -r $@ $?

All the .o files are created by the makefile.
It didn't work.

So, I tried to make the library with the command
Code:
arm-eabi-ar -r libpekee.a main.o  TCPClient.o  WDevice.o  WDriver.o  WNetworkObjectTransport.o  WRobot.o  WRobotPekee.o  WServiceDirectory.o

but it appeared that the "arm-eabi-ar" command is not know by my system (Ubuntu 6.10).

Back to Windows, and the command worked! At last I got my "libpekee.a".

as PypeBros said in the beginning of the discussion
Quote:
then you simply include the ".a" file in the list of libraries, e.g.
Code:
LIBS   := $(DSROOT)/runme/libpppds.a -lnds9 -ldswifi9 -lfat


I try this in the makefile of my DS project:
Code:
LIBS   := $(INCLUDE)/plop/libpekee.a -lfat -lnds9 -ldswifi9


But the result is the same
Code:
d:/devkitPro/PA_Pekee/Main-boutons-cible-formes-spatiale/source/main.cpp:39: undefined reference to `WRobotPekee::WRobotPekee()'
d:/devkitPro/PA_Pekee/Main-boutons-cible-formes-spatiale/source/main.cpp:186: undefined reference to `WRobotPekee::~WRobotPekee()'


@Lick
I also tried your proposal, but it didn't work. I still got some "undefined reference to `WRobotPekee::WRobotPekee()' ".

Maybe there is a special place to define some special stuff?