Linking order

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Strapping Scherzo
DC Developer
DC Developer
Posts: 2285
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Fri Feb 21, 2003 7:37 am
Location: Chicago, IL
Has thanked: 0
Been thanked: 1 time
Contact:

Linking order

Post by Strapping Scherzo »

Does startup.o have to be the first in the list of object files when linking? I'm just curious if this is my booting problem.
Image
nymus
DC Developer
DC Developer
Posts: 968
Joined: Tue Feb 11, 2003 4:12 pm
Location: In a Dream
Has thanked: 5 times
Been thanked: 6 times

Post by nymus »

is your program not "booting" or not "linking"?

I think it depends on the way your files reference each other.

If you have file1.c that calls functions from file2.c, file 1.c must come first in the link line. (I think)
behold the mind
inspired by Dreamcast
Strapping Scherzo
DC Developer
DC Developer
Posts: 2285
Joined: Fri Feb 21, 2003 7:37 am
Location: Chicago, IL
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Strapping Scherzo »

It was not booting and I fixed it. It was the link order. Note to all programmers: startup.o must come first in the link command. It doesn't matter for serial upload because dc-load already has it's startup code in memory. I'm uploading a new pre-pre-pre-alpha of Sper Famicast to my website right now.
Image
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Are you using a custom makefile for this, by any chance? If you're using a makefile like the ones the KOS examples use, it's taken care of by the makefile template thingy that the makefile includes.
User avatar
Arqueiro
DCEmu Nutter
DCEmu Nutter
Posts: 785
Joined: Tue Jul 02, 2002 9:29 am
Has thanked: 0
Been thanked: 0
Contact:

Post by Arqueiro »

scherzo wrote:It was not booting and I fixed it. It was the link order. Note to all programmers: startup.o must come first in the link command. It doesn't matter for serial upload because dc-load already has it's startup code in memory. I'm uploading a new pre-pre-pre-alpha of Sper Famicast to my website right now.
good woek man !!! i see the news about this emulator ! vary good job!

do u already found one to program the ASM code ? this is a hard part of your work...

sorry but i dont know ASM :(
but i like to help you in other things if you want !
3d graphics and visualization ?
http://www.arquiteturadigital.com
Strapping Scherzo
DC Developer
DC Developer
Posts: 2285
Joined: Fri Feb 21, 2003 7:37 am
Location: Chicago, IL
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Strapping Scherzo »

BlackAura wrote:Are you using a custom makefile for this, by any chance? If you're using a makefile like the ones the KOS examples use, it's taken care of by the makefile template thingy that the makefile includes.
I'm using Dev-C++ configured to use a precompiled sh4 toolchain and KOS libs. I picked them up from links in this thread:
http://www.dcemulation.org/phpBB/viewtopic.php?t=38963
Dev-C++ lists the object files on the linker's command line in the order the source files were added to the project AND it puts the custom parameters for the linker (where I had startup.o) at the end of command line. So I just had to write a post step in the makefile that linked with startup.o first. So I'm actually linking twice now, overwriting the first elf. Maybe I can stop Dev-C++ from doing it's link but it's pretty harmless as it is right now.

Once I figure out all these little quirks of using Dev-C++ as an IDE for Dreamcast Development, I'd like to release a zip of my Dev-C++ so that people can setup a development environment on windows in just about one step.
Image
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Ah, it's a DevC++ thing. I've never managed to get that to work acceptably.
ragnarok2040
DC Developer
DC Developer
Posts: 462
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Post by ragnarok2040 »

I managed to get it to work, but there seems to be different issues for different people. I bet it might be a ntfs/fat32/win98 or win2k/xp type of compatability issue. I got it to work by setting up the Dreamcast compiler like it says, except using mingw32-make.exe instead of regular make.exe in dev-cpp's bin folder. I also had to remove the rm lines from the dreamcast.mak files, because the rm lines were giving an error about nothing to remove, even though it should've just warned.. or something. After I had done all that, it worked quite well, actually.
User avatar
JMD
Insane DCEmu
Insane DCEmu
Posts: 234
Joined: Wed Dec 11, 2002 6:45 am
Location: A Melody From a Past Life Keeps Pulling Me Back
Has thanked: 0
Been thanked: 0
Contact:

Post by JMD »

Hi,

My project compiled with Dev C++ run fine with code cable but refuse to boot with Demo Menu.
scherzo wrote:I just had to write a post step in the makefile that linked with startup.o first.
How did you that ?

Thanks.
Image
There is the theory of Möbius. A twist in the fabric of space where time becomes a loop
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

Code: Select all

all-before:
	rm -f romdisk.img romdisk.o
	genromfs -f romdisk.img -d romdisk -v
	bin2o romdisk.img romdisk_boot romdisk.o

[b]all-after :[/b]
#	dc-tool -e -x $(BIN)
	sh-elf-gcc startup.o <blah blah blah, object files>-o $(BIN) -L"C:/Dev-Cpp/dclib" -ml -m4-single-only -nostartfiles -nostdlib -Wl,-Ttext=0x8c010000 romdisk.o -lmp3 -loggvorbisplay -lparallax -lkmg -lpng -ljpeg -lkglx -lkallisti -lz -lm -lgcc -lk++
	sh-elf-strip $(BIN)	
User avatar
JMD
Insane DCEmu
Insane DCEmu
Posts: 234
Joined: Wed Dec 11, 2002 6:45 am
Location: A Melody From a Past Life Keeps Pulling Me Back
Has thanked: 0
Been thanked: 0
Contact:

Post by JMD »

Thanks WillSams

I tried many times but I it's got a pbm with the Windows style folder :

Code: Select all

sh-elf-gcc.exe startup.o main.o Text.o utils.o myGraphLib.o Game.o Pause.o HScore.o Menu.o -o "shangai.elf" -L"C:/Program Files/Dev-Cpp/dclib" -ml -m4-single-only -nostartfiles -nostdlib -Wl,-Ttext=0x8c010000 startup.o romdisk.o -loggvorbisplay -lpng -lz -lm -lkallisti -lgcc 
error :

Code: Select all

make.exe: *** No rule to make target `/Program', needed by `main.o'.  Stop.
I think I don't have the same make.exe than you because the syntax

Code: Select all

all-before:
   rm -f romdisk.img romdisk.o
   genromfs -f romdisk.img -d romdisk -v
   bin2o romdisk.img romdisk_boot romdisk.o 
don't run on my install

Code: Select all

dreamcast.mak:2: *** missing separator.  Stop.
I must use :

Code: Select all

romdisk.img:
	genromfs -f romdisk.img -d romdisk -v

romdisk.o: romdisk.img
	bin2o romdisk.img romdisk romdisk.o

all-before: romdisk.o
I made few weeks ago a doc (sorry it's in french) of how to install Dev-C++ with l@Cible
Image
There is the theory of Möbius. A twist in the fabric of space where time becomes a loop
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by speud »

did you try to replace the folder names by dos style names? is i remember correctly it takes the 6 first chars and put a ~1 at the end, for example Program Files becomes Progra~1
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Has thanked: 0
Been thanked: 0
Contact:

Post by GPF »

or maybe use

/cygdrive/c/Program\ Files/Dev-Cpp/dclib

if under cygwin

the point is you have to escape the space with a backslash even though I thought the "quotes" around it should have worked anyway
Storminator16
DCEmu Veteran
DCEmu Veteran
Posts: 850
Joined: Mon Sep 01, 2003 11:12 am
Location: NC/Iraq
Has thanked: 0
Been thanked: 0
Contact:

Post by Storminator16 »

He's using Dev-C++ ;)
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Has thanked: 0
Been thanked: 0
Contact:

Post by GPF »

Didn't realize that it was under dev-cpp, I only used it as an editor then used the command line under mingw to compile :)
sh-elf-gcc.exe startup.o main.o Text.o utils.o myGraphLib.o Game.o Pause.o HScore.o Menu.o -o "shangai.elf" -L"C:/Program Files/Dev-Cpp/dclib" -ml -m4-single-only -nostartfiles -nostdlib -Wl,-Ttext=0x8c010000 startup.o romdisk.o -loggvorbisplay -lpng -lz -lm -lkallisti -lgcc
shouldn't it be

Code: Select all

sh-elf-gcc.exe startup.o main.o Text.o utils.o myGraphLib.o Game.o Pause.o HScore.o Menu.o -o "shangai.elf"  -ml -m4-single-only -nostartfiles -nostdlib -Wl,-Ttext=0x8c010000 startup.o romdisk.o -L"C:/Program Files/Dev-Cpp/dclib" -loggvorbisplay -lpng -lz -lm -lkallisti -lgcc 
because the -L is the location of the lib directory not that will eliminate the space problem between Program and Files

maybe use

Code: Select all

c:\\Program\ Files\\Dev-Cpp\\dclib
or

Code: Select all

C:/Program\ Files/Dev-Cpp/dclib
speud
DCEmu Uncool Newbie
DCEmu Uncool Newbie
Posts: 1459
Joined: Sat Dec 27, 2003 10:40 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by speud »

i dont know about dev-c++ but i had the same problem with other programs before, in the command line i tried to put the path between " like he did but it didnt work, so i removed them and wrote the path in dos style and it worked, it was under windows xp
http://blueswirl.fr.st - DC Online Tools and Downloads

thx to Wack0 for the avatar ;)
User avatar
JMD
Insane DCEmu
Insane DCEmu
Posts: 234
Joined: Wed Dec 11, 2002 6:45 am
Location: A Melody From a Past Life Keeps Pulling Me Back
Has thanked: 0
Been thanked: 0
Contact:

Post by JMD »

The ~ seems to works.
Now all compile right (without makefile errors) but there is only the normal Dev-C++ output.
... I will search a little than give you feedback.

Thanks.
Image
There is the theory of Möbius. A twist in the fabric of space where time becomes a loop
User avatar
JMD
Insane DCEmu
Insane DCEmu
Posts: 234
Joined: Wed Dec 11, 2002 6:45 am
Location: A Melody From a Past Life Keeps Pulling Me Back
Has thanked: 0
Been thanked: 0
Contact:

Post by JMD »

Ok,

I found solution to my makefile pbm. I googled and find this.
It was a stupid pbm beetween tab and spaces so I edit the file with notepad :).

Here is my new makefile :

Code: Select all

LIBS2 = $(patsubst startup.o, ,$(LIBS))
BIN2 = $(patsubst %.elf,%.el2,$(BIN))
RBIN = $(patsubst %.elf,%.bin,$(BIN))
FBIN = 1st_read.bin


romdisk.img : 
	genromfs -f romdisk.img -d romdisk -v

romdisk.o : romdisk.img
	bin2o romdisk.img romdisk romdisk.o

all-before : romdisk.o
	
$(BIN2) : $(BIN)
	$(CC) startup.o $(LINKOBJ) -o $(BIN2) $(LIBS2)

Strip : $(BIN2)
	sh-elf-strip $(BIN2)

$(RBIN) : Strip
	sh-elf-objcopy -O binary  $(BIN2) $(RBIN)

all-after : $(RBIN) 
	scramble $(RBIN) $(FBIN)
When I use a variable, I've no more pbm with long file names.

And the end of my compilation log :

Code: Select all

sh-elf-gcc.exe main.o Text.o utils.o myGraphLib.o Game.o Pause.o HScore.o Menu.o  -o "Maqiupai.elf" -L"C:/Program Files/Dev-Cpp/dclib" -ml -m4-single-only -nostartfiles -nostdlib -Wl,-Ttext=0x8c010000 startup.o romdisk.o -loggvorbisplay -lpng -lz -lm -lkallisti -lgcc -nostdlib 

sh-elf-gcc.exe startup.o main.o Text.o utils.o myGraphLib.o Game.o Pause.o HScore.o Menu.o  -o Maqiupai.el2 -L"C:/Program Files/Dev-Cpp/dclib" -ml -m4-single-only -nostartfiles -nostdlib -Wl,-Ttext=0x8c010000   romdisk.o -loggvorbisplay -lpng -lz -lm -lkallisti -lgcc -nostdlib 

sh-elf-strip Maqiupai.el2

sh-elf-objcopy Maqiupai.el2 Maqiupai.bin

scramble Maqiupai.bin 1st_read.bin

Execution terminated
We can see the 2 compils, the strip, the objcopy and the scramble.

The second elf (el2 : the elf after the strip) work's fine with the coder cable and DC-Tool.

BUT (I begin to feel a bit bored now :cry: ),
When I use DemoMenu to run my file (I use the DCEvolution Xmas Disc's one), no file runs.
I tried the bin, the 1st...bin and the el2 (file after strip).

Where is the pbm ? In the DemoMenu version, In the compil order ?

Have you got any ideas ?

Thanks
Image
There is the theory of Möbius. A twist in the fabric of space where time becomes a loop
User avatar
JMD
Insane DCEmu
Insane DCEmu
Posts: 234
Joined: Wed Dec 11, 2002 6:45 am
Location: A Melody From a Past Life Keeps Pulling Me Back
Has thanked: 0
Been thanked: 0
Contact:

Post by JMD »

That's works fine now.

I updated the example on my last post to be correct.
Image
There is the theory of Möbius. A twist in the fabric of space where time becomes a loop
Post Reply