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.

Beginners > Static Compiling

#166164 - semihce - Sat Jan 31, 2009 11:18 pm

Hello there,

I am developing a GBA project in Visual Studio and i need to compile this project statically so that i can use this project in other projects. A GBA developer told me that you must change the "makefile" in order to do this. Other options such as win32 project creation in Visual Studio doesnt work.

How can i build this project statically. please help me.. this is a bachelor thesis..

#166176 - silent_code - Sun Feb 01, 2009 1:09 pm

You want to build a static library, is that right?
There is at least one makefile for libraries in the examples. I think in the templates sub-folder.

Otherwise, you could download libgba or libnds and take a look at their makefiles.

Good luck and have a nice Sunday!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#166183 - semihce - Sun Feb 01, 2009 3:49 pm

Yes, definitely i want to build a static library, you are right.

But i didnt understand which templates sub-folder?.. Please help me to find this kind of makefiles.


silent_code wrote:
You want to build a static library, is that right?
There is at least one makefile for libraries in the examples. I think in the templates sub-folder.

Otherwise, you could download libgba or libnds and take a look at their makefiles.

Good luck and have a nice Sunday!

#166186 - kusma - Sun Feb 01, 2009 4:23 pm

You are using more than just visual studio, right? 'Cause visual studio doesn't support GBA development out of the box.

#166189 - semihce - Sun Feb 01, 2009 5:14 pm

I entegrated GBA into Visual Studio. But i am using only visual studio. This link tells how to entegrate GBA into visual studio.
http://www.brandorf.com/?p=315

#166191 - kusma - Sun Feb 01, 2009 5:36 pm

GBAAppWizard does not seem to include static library projects, so you'll either have to learn to use makefiles, or just include the same source-files in multiple projects.

#166198 - semihce - Sun Feb 01, 2009 7:52 pm

User silent_code has written that there are such makefiles, please send me if you find one of them.

#166203 - silent_code - Sun Feb 01, 2009 10:29 pm

Well, download the libNDS examples provided by devkitPro, then go to templates and check out arm9lib's makefile. It should include all the settings needed to convince gcc to build a static library.

Good luck. :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#166209 - semihce - Sun Feb 01, 2009 11:41 pm

Thanks silent_code

#167844 - semihce - Tue Mar 31, 2009 2:40 am

Below i am giving the makefile i use in my project. Can someone help me with static building of this project? Which changes should i make to this makefile?

Here is the makefile:


Code:
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
endif

-include $(DEVKITARM)/gba_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output, if this ends with _mb a multiboot image is generated
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
# HAM Stuff no longer used ....
#
#PROGNAME =unused
#OFILES+= unused
#ADD_LIBS+= unused   

# .................
#

TARGET      :=   $(shell basename $(CURDIR))
BUILD      :=   build
SOURCES      :=   source
DATA      :=   
INCLUDES   :=   $(DEVKITARM)
GDB_DIRS   =    $cdir:$cwd:$(ADD_GDB_SOURCE_DIRS)

ifeq ($(MAKECMDGOALS),gdb)
DEBUG_SET   :=   gdb
endif

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
#ARCH   :=   -mthumb -mthumb-interwork
ARCH   :=

ifneq ($(DEBUG_SET),gdb)
THIS_BUILD   :=   "Release Build"
CFLAGS   :=   -Wall -O3 -save-temps \
         -mcpu=arm7tdmi -mtune=arm7tdmi\
          -fomit-frame-pointer\
         -ffast-math \
         $(ARCH)
ASFLAGS   :=   $(ARCH)
else
THIS_BUILD   :=   "Debug Build"
CFLAGS   :=   -g -Wall -O0 -save-temps \
         -mcpu=arm7tdmi -mtune=arm7tdmi\
         -ffast-math \
         $(ARCH)
ASFLAGS   :=   $(ARCH) -g
endif
CFLAGS   +=   $(INCLUDE)



ifneq ($(DEBUG_SET),gdb)
LDFLAGS   =   $(ARCH) -Wl,-Map,$(notdir $@).map
else
LDFLAGS   =   -g $(ARCH) -Wl,-Map,$(notdir $@).map
endif

#---------------------------------------------------------------------------------
# path to tools - this can be deleted if you set the path to the toolchain in windows
#---------------------------------------------------------------------------------
export PATH      :=   $(DEVKITARM)/bin:$(DEVKITPRO)/msys/bin:$(PATH)

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS   :=

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS   :=   $(LIBGBA)

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT   :=   $(CURDIR)/$(TARGET)
export VPATH   :=   $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
               $(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR   :=   $(CURDIR)/$(BUILD)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES      :=   $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES   :=   $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES      :=   $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES   :=   $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
   export LD   :=   $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
   export LD   :=   $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES   := $(addsuffix .o,$(BINFILES)) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE   :=   $(foreach dir,$(INCLUDES),-I$(dir)/include) \
               $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
               $(foreach dir,$(CURDIR), -I$(dir)/include) \
               -I$(CURDIR)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS   :=   $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
   @[ -d $@ ] || mkdir -p $@
   make "DEBUG_SET=$(DEBUG_SET)" --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

all   : buildtype $(BUILD)

buildtype:
   @echo "Build type: " $(THIS_BUILD)

#---------------------------------------------------------------------------------
clean:
   @echo clean ...
   rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba

#---------------------------------------------------------------------------------
vbawin:   clean all
   $(DEVKITPRO)/tools/win32/vbawin.exe $(TARGET).gba

#---------------------------------------------------------------------------------
runvbawin:
   $(DEVKITPRO)/tools/win32/vbawin.exe $(TARGET).gba

#---------------------------------------------------------------------------------
vba:   clean all
   $(DEVKITPRO)/tools/win32/vbaSDL/vba.exe -3 $(TARGET).gba

#---------------------------------------------------------------------------------
runvba:
   $(DEVKITPRO)/tools/win32/vbaSDL/vba.exe -3 $(TARGET).gba

#---------------------------------------------------------------------------------
startsdl:
   $(DEVKITPRO)/tools/win32/vbaSDL/vba.exe -3 -Gtcp:44444 &

#---------------------------------------------------------------------------------
makeini:
   echo "File $(TARGET).elf" > insight.ini
   echo "target remote 127.0.0.1:44444" >>insight.ini
   echo "load $(TARGET).elf" >>insight.ini
   echo "b main" >>insight.ini
   echo "directory $(GDB_DIRS)">>insight.ini
   echo "c" >>insight.ini

#---------------------------------------------------------------------------------
startinsight:
   $(DEVKITPRO)/insight-6.4.50/bin/arm-elf-insight.exe --command=insight.ini $(TARGET).elf

#---------------------------------------------------------------------------------
gdb:   clean
   rm -f gdbtk.ini
   rm -f /c/gdbtk.ini
   @make "DEBUG_SET=$(DEBUG_SET)" all
   make startsdl makeini startinsight

#---------------------------------------------------------------------------------
rungdb: startsdl makeini startinsight

testinsight: makeini startinsight

#---------------------------------------------------------------------------------
else

DEPENDS   :=   $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------

$(OUTPUT).gba   :   $(OUTPUT).elf

$(OUTPUT).elf   :   $(OFILES)

%.o   :   %.pcx
   echo $(notdir $<)
   $(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#--------------------------------------------------------------------------------
[/code]

Last edited by semihce on Fri Apr 03, 2009 3:41 am; edited 1 time in total

#167860 - elyk1212 - Wed Apr 01, 2009 1:29 am

All you need is something like this:

Code:


# Keep the names of all cpp source files, and change their extension to .o
LIBOFILES      = $(LIB_FILES:%.cpp=%.o)       

# all is the default rule
all   : libraryname.a

# remove the old library and recreate the lib file
libraryname.a:   $(LIBOFILES)
   rm -f $@
   ar crs $@ $(LIBOFILES)


Granted it's a bit simple, I halfway stole it from http://www.cs.duke.edu/~ola/courses/programming/libraries.html changing a few things

Anyhow, it pays to understand what it does. Do a man on ar to get details on the archiver and read a few tutorials on GNU Makefiles.

The first line takes all the names of your cpp files and changes the extension to .o and saves them in LIB_FILES

So, if you are building this library to be used in a project, I'd have a separate folder for the library and make your own customized makefile for the library that contains these details (make it more of a modular file tree that way).

Be sure you have a rule to compile the libraries cpp files though!

Code:


# Put something  like this in your library Makefile
#     (Assuming you have your flags to g++ contained in a CFLAGS variable)
%.o: %.cpp
   $(CXX) $(CFLAGS) -c $*.cpp

#167873 - semihce - Wed Apr 01, 2009 4:25 pm

I will try to understand what is told in the link you gave elyk1212.
But it is very difficult for me now. I'll return here after studying a little bit more.

#167874 - elyk1212 - Wed Apr 01, 2009 5:12 pm

Ask away, my friend. I will do my best to answer any questions.

Also, you may want to start with a generic Makefile tutorial to get a grasp on what all the symbols actually mean, syntax etc:

Exhaustive docs:
(Start here in the Introduction links, to understand terms etc)
http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_toc.html

Learn by Examples:
http://mrbook.org/blog/tutorials/make/

The main thing is..

-- That target with ar makes a static library from your already compiled object files.

I always say, try some thing new with something trivialy simple before using it on a big 'ol project.

Just try this static library Makefile with a simple program.. say ... with a cpp file containing an empty function.

Code:

// Within test.cpp
void doNothing()
{


}


Have your make file be something even more simple if the wild cards are throwing you off (the % symbols and such):
Code:

# Set your library file name here
LIBNAME = libraryname.a

# Keep the names of all cpp source files, and change their extension to .o
LIBOFILES      =  test.o   

# all is the default rule
all   : $(LIBNAME)

# remove the old library and recreate the lib file
$(LIBNAME):   $(LIBOFILES)
   rm -f $(LIBNAME)
   ar crs $@ $(LIBOFILES)

# Compile your small,  test.cpp file
#     (Assuming you have your flags to g++ contained in a CFLAGS variable)
test.o: test.cpp
   $(CXX) $(CFLAGS) -c test.cpp


Then add more complex stuff as you understand them.

#167877 - semihce - Wed Apr 01, 2009 9:24 pm

How can i try a simple makefile for a simple project. I have a big project and one makefile regarding that project.
This project and its makefile work on Visual Studio. It means I embedded GBA into Visual Studio and worked with this so far.
How can I compile an application with a makefile? Now i am installing Cygwin, i hope it works..

#167878 - kusma - Wed Apr 01, 2009 10:12 pm

semihce wrote:
Now i am installing Cygwin, i hope it works..

Don't. Cygwin is only known to cause trouble with devkitARM. Why do you think installing it will help you?

#167880 - semihce - Wed Apr 01, 2009 10:27 pm

Then what do you advice me? How can i compile a file without installing Cygwin?

HEY EVERYBODY, I AM EDITING THIS CODE...

I want to stress that i am NEW in makefiles. I need to build my project statically but since i dont know anything about makefiles I want to study makefiles. So i think i need something like gcc compiler. If you say that there is no need for gcc compiler and Visual Studio is enough for this, how?

Namely, I only need a compiler to try my makefiles in simple(such as hello.cpp) applications.


Last edited by semihce on Wed Apr 01, 2009 11:49 pm; edited 1 time in total

#167881 - elyk1212 - Wed Apr 01, 2009 11:08 pm

VisualStudio integration, Cygwin?... good night. I just use the Linux console and use vim.. no need to integrate or lose sleep that way :P

I am sure though that Visual Studio has an option to use a particular Makefile that you have hand crafted. If your current method of integration works, it probably is best to stick with that.

If your question is on more than one make file, you can call a make file from within another make file, no problemo :)
Code:


all: makelib... # Make sure your target below is a dependency within your first target
     #Where you're making your GBA elf and all that

makelib:
     # within yourlibdir/, you need to have a Make file called Makefile :)
     make -C yourlibdir



Or if your library is peppered in with your other non library source (unorganized and I don't recommend this directory structure :P)

Code:


all: makelib... # Make sure your target below is a dependency within your first target
     #Where you're making your GBA elf and all that

makelib:
     make -C libMakefile



Then just use the method you were using before, and add some stuff to your current makefile.

But, I recommend doing that trivial example I showed you first and playing to get an understanding on what's going on before attempting to integrate the changes in the big project.


Warning Opinionated message:
So.. I hope other on lookers can see the issue with using IDE's as they obscure many details.. and then when we really need something done, that is more than a trivially compile customization, it can become a huge pain. And this pain is multiplied on each new IDE release that "does things a little differently". Oh well, each method has its pits I suppose.

This doesn't sound necessary, since you already have a custom Makefile working with Visual Studio, but if not:
I would say to start by reading the Visual Studio documentation on custom/manual Makefiles. I am sure just pointing to the file and auto running a few shell commands should not be a big deal.

But anyhow, to test, you can use what ever Windows->Linux/GNU environment emulator's console that works with DevkitArm (no idea what it is, MinGW console?) and just type 'make', once you have created that trivial example I've shown you.

Then, when you understand it, integrate it into your larger project.

Believe me, you don't want to start complex... you want to start simple and add to it to get things working.

#167882 - Kath - Wed Apr 01, 2009 11:33 pm

I've been using the VS wizard from this thread. It's useful when you want to start a project to test something or make a small app. It seems to support VS Express C++ 2008 fine and everything works such as Intellisense, compile output window, pressing F7 to build etc. You can also change the makefile in VS and recompile nice and quickly.

It gives you the options for:

- ARM9 project. libnds ARM7 binary.
- ARM9/ARM7 project.
- DS Library Project.

It uses the templates from libnds I think. The "Library" project probably makes a .lib but I haven't used it before. If you set no$gba as the debugger you can just press F5 to compile then run right away in Windows which is 10x better than writing it to a sd card and turning on your DS :p

#167884 - kusma - Thu Apr 02, 2009 12:01 am

semihce wrote:
Then what do you advice me?

The same as I advised you earlier: Sit down and learn how to write Makefiles. You can do this without Cygwin - devkitARM has everything you need for that task.

#167889 - semihce - Thu Apr 02, 2009 2:23 am

Quote:
You can do this without Cygwin - devkitARM has everything you need for that task.


How can i do this with devkitARM, can you a bit describe this? I have searched the web but couldn't find anything :(

#167892 - elyk1212 - Thu Apr 02, 2009 6:23 am

Quote:

How can i do this with devkitARM, can you a bit describe this? I have searched the web but couldn't find anything :(


To use DevkitArm?..., you already were doing this.. from what I can gather on your previous postings. Devkitarm is just a collection of tools, gcc/g++, c/c++ headers and standard libraries ...etc (prob more on windows versions).

Just do what you were doing before, since it was working (using Visual studio with the template makefile). Then make some edits to the template and "see what happens".

This can be your testing grounds if you will not try something small as I was suggesting.

But I really do recommend reading the basics of the Makefile docs in the links I gave you, and try out a few concepts, as you go, to get a hold on what they mean, and I recommend doing this on a small project that would take just a few minutes to produce.

Start with one source file, then move to multiples, when you learn how to glob files with make. .. or just add them explicitly by name.

Unimportant side note:

This seems to be an OK method, as even Autotools (not used by Devkitarm so don't worry if you don't know what it is) expects this style [explicit adding], and it reminds me to add to Subversion repositories on projects, when I have to add the file explicitly somewhere.

#167907 - semihce - Fri Apr 03, 2009 2:40 am

Hello eveyone,

I've studied makefiles using MinGW and i know something about makefiles now.
I've even generated a static library for hello.cpp using this makefile below:

Code:
NAME=hello
CPP=g++

all: libraryname.a after-lib

clean:
   rm ${NAME}.exe *.o *.a

after-lib:
   rm *.o

LIBOFILES = ${NAME}.o

libraryname.a: $(LIBOFILES)
   rm -f $@
   ar cq $@ $(LIBOFILES)
   
${NAME}.o: ${NAME}.cpp ${NAME}.h
   ${CPP} -g -c ${NAME}.cpp -o ${NAME}.o



My OLD MAKEFILE(which I gave in previous page) already generates object files of each .cpp files.
So, I thought that there is no need to generate object files of each cpp files and i just used them to generate a static library.
Then, i used this makefile to generate a static library of existing object files:

Code:
all: libstatic.a

LIBOFILES = *.o

StaticLib.a: $(LIBOFILES)
   rm -f $@
   ar cq $@ $(LIBOFILES)


It generated a static library as i wanted. I included this libstatic.a and corresponding header files in my project but when I run the project, it gave me errors.
Below I am giving one of these errors:

undefined reference to `theFunctionIHaveUsed()'

WHY DO I GOT THIS ERROR, DO YOU HAVE ANY IDEA?

#167916 - nanou - Fri Apr 03, 2009 12:25 pm

Is it in the link step or the compile step?

Ensure that you've included all the needed headers (with the function prototypes) in your source files and that it's actually being linked.
_________________
- nanou

#167919 - semihce - Fri Apr 03, 2009 2:21 pm

As I said,
Quote:
I included libstatic.a and corresponding header files

What is more, I learned that I must include the static library like this,

Code:
g++ -o main main.cpp -lstatic

Now I am trying to do this..

#167923 - elyk1212 - Fri Apr 03, 2009 3:43 pm

semihce wrote:
As I said,
Quote:
I included libstatic.a and corresponding header files

What is more, I learned that I must include the static library like this,

Code:
g++ -o main main.cpp -lstatic

Now I am trying to do this..


Quote:

undefined reference to `theFunctionIHaveUsed()'


Typically this error means that you forgot to do a #include header.h within the file you are compiling, both main.cpp and hello.cpp should both contain this.

By assumption, looking at your makefile, this should be hello.h... but I don't know by just looking. You need to grep for the function name theFunctionIHaveUsed, and see where it is defined (which header).

Yes, and you do ALSO need to link against the library, in whatever program that will use the library. But you won't run into this until you fix the name resolution (headers all included in correct areas). You would have gotten obj link errors (from not including your static lib), if if got past the name resolution compilation step.

Additionally, you need to make sure gcc is actually looking in the correct directory for your lib!

Code:


#The path to your library.  This can be a relative path if it is in a
#  subdirectory of the project you're using the library in
# e.g.
# LIBPATH = -Lsubdir_to_libraryname.a/
LIBPATH += -L/your_lib_/

# Needs to be your library name
LIBS =  -llibraryname

# Your old command looked off, the -o should be before
#     the name of the executable you wish to produce
#     and there is no need to recompile main.cpp to main.o again, you should
#    have done that before the linking stage
$(CPP) $(LIBPATH) main.o $(LIBS) -o  main


Last edited by elyk1212 on Fri Apr 03, 2009 4:13 pm; edited 1 time in total

#167925 - elhobbs - Fri Apr 03, 2009 3:55 pm

make sure you do not have any warnings about undeclared functions in the compiling stage.

#167928 - elyk1212 - Fri Apr 03, 2009 4:49 pm

Oh, BTW, you know to do this in header files right? (Notice ifndef... etc)

Code:

#ifndef YOUR_HEADER_H_
#define YOUR_HEADER_H_

class SuperCoolClass
{
   // Blah blah blah
};


#endif  /*  YOUR_HEADER_H_ */


This avoids multiple definition errors.

#167953 - semihce - Sat Apr 04, 2009 4:54 pm

I included the static library like this,

Code:
#------------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#------------------------------------------------------------------------------------
LIBS   := -L libstatic.a

#------------------------------------------------------------------------------------
# $(CURDIR)/source ==>> This is the directory that keeps libstatic.a and all .h files
#------------------------------------------------------------------------------------
LIBDIRS   :=   $(LIBGBA) -L$(CURDIR)/source


But i get the same(undefined reference to `theFunctionIHaveUsed()' ) errors..

How should i include this static library?

#167954 - Ruben - Sat Apr 04, 2009 5:05 pm

It's not capital L, so it'd be

-lstatic

When using -L, it specifies library *directories*, using -l means that it has to load, from those directories, a file called libfoo.a where foo is the name of the library after the l

#167956 - semihce - Sat Apr 04, 2009 5:28 pm

I have already tried this
Code:
LIBS   := -lstatic

But i got this error now,

c:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.3.2/../../../../arm-eabi/bin/ld.exe: cannot find -lstatic

#167957 - Ruben - Sat Apr 04, 2009 5:30 pm

Are you sure that you've specified the library directories in LIBDIRS?

#167958 - semihce - Sat Apr 04, 2009 5:33 pm

I dont know how can i specify it? Can you please tell it to me..

$(CURDIR)/source

This code must give the directory that libstatic.a exist.

#167959 - Ruben - Sat Apr 04, 2009 5:35 pm

Then you can specify these flags..

-L$(CURDIR)/source -lstatic

Though I don't know why you'd place the library in the source folder.. why not place it in a "lib" folder?

#167960 - semihce - Sat Apr 04, 2009 5:41 pm

I've just tried it, i get the same cannot find -lstatic error. :(

You are right, i should include it to a lib folder, but this is just for try. I just want to see something working

#167961 - Ruben - Sat Apr 04, 2009 5:44 pm

Another thing I can think of since that didn't work either, is that at link time, you're not in the right directory (like, you could be in directory build, for example) so it's looking for build/source/libstatic.a instead of just source/libstatic.a. To avoid this, make another variable like this..

Code:
TOPDIR    :=    $(CURDIR)

# Rest of your makefile..
# And when you go to link, use $(TOPDIR)/source rather than $(CURDIR)/source

#167964 - semihce - Sat Apr 04, 2009 5:51 pm

Still the same error.. Do you know any method to print the $(CURDIR) to the command line?

#167965 - Ruben - Sat Apr 04, 2009 5:52 pm

Code:
# Not sure if it'll work, but it may be...
echo $(CURDIR)

#167966 - semihce - Sat Apr 04, 2009 5:54 pm

I've tried it before asking you:). It didnt work..

#167967 - Ruben - Sat Apr 04, 2009 5:57 pm

Well, the only other things that comes to my mind is that you compiled C++ source and its name mangling was different to the one you're using with the other one. If you compiled C code, then make sure you're using extern "C" with the prototypes.

#167969 - semihce - Sat Apr 04, 2009 6:51 pm

Ok guys, I have solved the problem :).. Finally..

THANKS FOR ALL YOUR HELP

This is the change I've done..
Code:
export LIBPATHS   :=   $(foreach dir,$(LIBDIRS),-L$(dir)/lib) -L$(MYSTATICLIBDIR)/source/lib


As you see, instead of writing the path to the LIBDIRS, I wrote it to the LIBPATHS.. So, it is working now..

#167972 - elyk1212 - Sat Apr 04, 2009 7:30 pm

Congrats! Hope you have learned a lot from your struggles, I always seem to when I have to work a bit.

Well, I looked at that Makefile you emailed me and yeah, you had a variable named LIBPATHS and LIBDIRS. Appears you can eliminate the LIBDIRS variable.

EDIT: LOL, no don't eliminate LIBDIRS. It's used in LIBPATHS definition. :O

It seems you were combining many Makefiles together etc. Make sure you know which variable is being used. If you follow all makefiles included, down to the granularity of actually calling the linker, you'll find that LIBPATHS is the only variable used (at least in modern DevkitARM, cannot say about previous ones).

EDIT: Wrong: It's not the only one used, but still following it down helps.

Code:

# Where the LIBPATHS is used in the linking step

-include $(DEVKITARM)/gba_rules

#          Compile step is done in $(DEVKITARM)/base_rules


From $(DEVKITARM)/gba_rules
Code:


#---------------------------------------------------------------------------------
%_mb.elf:
   @echo linking multiboot
   @$(LD) -specs=gba_mb.specs $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@

#---------------------------------------------------------------------------------
%.elf:
   @echo linking cartridge
   @$(LD)  $(LDFLAGS) -specs=gba.specs $(OFILES) $(LIBPATHS) $(LIBS) -o $@


So, when in doubt just try to follow down further till you actually can see what is being used, and you'll be set.


Last edited by elyk1212 on Tue Apr 07, 2009 12:43 am; edited 2 times in total

#167975 - semihce - Sat Apr 04, 2009 8:36 pm

Thanks especially to you "elyk1212". You helped me a lot....

#168021 - elyk1212 - Tue Apr 07, 2009 12:40 am

No problem semihce.

Hey, I was overzealous in my last statement, don't eliminate the LIBDIRS variable. If you're using the default devkitARM makefile, you should be able to add your directory to LIBDIRS and it should work, unless you're redefining it again somewhere.

I think you're using some variant of the default makefile, just make sure LIBDIRS is defined before LIBPATHS.

To keep with convention, you should probably do something like this:

Code:


#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS   :=   $(MYSTATICLIBDIR)/source/lib



Code:


# MUST Be after you define LIBDIRS
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS   :=   $(foreach dir,$(LIBDIRS),-L$(dir)/lib)



That way the LIBPATHS construction does what you'd expect, hopefully.