xbox-scene.com - your xbox news information source
Quick Links: Main Forums | Xbox360 Forums | Xbox1 Forums | PS3 Forums
Xbox-Scene Forum Help  Search Xbox-Scene Forums   Xbox-Scene Forum Members   Xbox-Scene Calendar

Giganews Offers: days binary retention, 99%+ Completion, and Unlimited Access!
Try Giganews' no obligation free trial!

Support this site - buy the X-Scene Tshirt $17.95


Welcome Guest ( Log In | Register )

 Forum Rules Rules
2 Pages V  1 2 >  
Reply to this topicStart new topic
> Using C++ With Openxdk, A tutorial
kennelbound
post May 22 2005, 07:06 PM
Post #1


X-S Member
*

Group: Members
Posts: 63
Joined: 13-August 03
Member No.: 55925



I'm writing this from memory, so please excuse if its not 100%.

I use Bloodshed C++ (it's free and easy to use), but the basic steps should be about the same for any IDE (I will also paste in a working makefile that others can modify for those of you coding l33t style).

Basic Notes:

This assumes you have OpenXDK installed in the default location, that you've configured cygwin properly, and installed cygwin to C:\cygwin.

Setting up the IDE

1) Create a new Win32 Application, checking C++ project.
2) Goto Tools->Compiler Options
3) Click on the Plus to create a new Compiler, name it Xbox
4) Check the box next to 'Add these commands when calling compiler' and put the following into the box:
CODE
-c -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM

5) Check the box next to 'Add these commands to the linker command line' and put the following into the box:
CODE
-nostdlib -Wl,--file-alignment,0x20 -Wl,--section-alignment,0x20 -shared -Wl,--entry,_WinMainCRTStartup -Wl,--strip-all -lstdc++ -lSDL -lopenxdk -lhal -lc -lhal -lusb -lc -lxboxkrnl

6) Click on the Directories tab
7) Put "C:\cygwin\usr\local\openxdk\bin" (without quotes) into the bottom box and click the Add button.
8) Click the Libraries tab
9) Add the following directories:
CODE
C:\cygwin\usr\local\openxdk\i386-pc-xbox\lib
C:\cygwin\usr\local\openxdk\lib

10)Click the C Includes Tab
11)Add the following directories:
CODE
C:\cygwin\usr\local\openxdk\i386-pc-xbox\include
C:\cygwin\usr\local\openxdk\include
C:\cygwin\usr\local\openxdk\include\SDL

12)Click the C++ Includes tab, and add the same directories as in step 11.
13)Click the Binaries tab
14)Next to gcc put "i386-pc-xbox-gcc" (without the quotes)
15)Next to g++ put "i386-pc-xbox-g++" (without the quotes)
16)Next to windres put "i386-pc-xbox-windres" (without the quotes)
17)Click OK
18)Click Project->Project Options
19)Click on the Compiler tab
20)From the Compiler drop down box, select Xbox
21)Click on the Build Options tab
22)Check the box next to 'Override Output filename' and put "default.exe" in the box (without quotes)
23)Click OK

For all subsequent projects, you only need to do steps 1 and 18-23.

Setting up CXBE as a tool

1) Click Tools->Configure tools
2) Click the plus to add a tool
3) In the Title box put "CXBE" (without quotes)
4) In the Program box put "C:\cygwin\usr\local\openxdk\bin\cxbe.exe" (without
quotes)
5) In the Working Directory box put "<PROJECTPATH>" (without quotes)
6) In the Parameters box put:
CODE
-TITLE:"<PROJECTNAME>" -DUMPINFO:"<PROJECTNAME>.cxbe" -OUT:"default.xbe" default.exe

7) Click OK
8) Click Close

Setting up and Compiling the Code

1) Around any C libraries, you must put 'extern "C" {}'
2) Here's an example of the library calls:
CODE
// Includes
extern "C" {
#include <stdio.h>
#include <hal/xbox.h>
#include <SDL.h>
#include "Joystick.h"
#include "SDL_graphics.h"
#include <openxdk/debug.h>
}
#include "Settings.h"
#include "Menu.h"

3) The Joystick and SDL_graphics libraries are C libs, whereas the Settings lib contains a C++ class, and so is not externed
4) For the main execution call, use the following:
CODE
extern "C" void XBoxStartup(){

5) Once you have your code written, compile (by pressing CTRL-F11)
6) Click Tools->CXBE to create the xbe file
7) Upload and test the file on your xbox

Final Thoughts

This setup has worked just fine for me. I do not claim to be a C++ guru, but from my basic assembly classes, as I recall, extern tells the linker to look outside of the current file for the symbol, and you can specify whether to connect to a C or C++ lib in this manner.

I hope this helps everyone out there. If this doesn't work for you, I will be very soon
releasing an opensource app which utilizes C and C++ classes, so wait just a bit longer, and you will have the entire source to look into.

Working Makefile

CODE

# Project: Cher
# Makefile created by Dev-C++ 4.9.9.2

CPP  = i386-pc-xbox-g++
CC   = i386-pc-xbox-gcc
WINDRES = i386-pc-xbox-windres
RES  = Cher_private.res
OBJ  = Joystick.o SDL_graphics.o Settings.o Error.o Cher.o Menu.o $(RES)
LINKOBJ  = Joystick.o SDL_graphics.o Settings.o Error.o Cher.o Menu.o $(RES)
LIBS =  -L"C:/cygwin/usr/local/openxdk/i386-pc-xbox/lib" -L"C:/cygwin/usr/local/openxdk/lib" -nostdlib -Wl,--file-alignment,0x20 -Wl,--section-alignment,0x20 -shared -Wl,--entry,_WinMainCRTStartup -Wl,--strip-all -lstdc++ -lSDL -lopenxdk -lhal -lc -lhal -lusb -lc -lxboxkrnl -mwindows  
INCS =  -I"C:/cygwin/usr/local/openxdk/i386-pc-xbox/include"  -I"C:/cygwin/usr/local/openxdk/include"  -I"C:/cygwin/usr/local/openxdk/include/SDL"
CXXINCS =  -I"C:/cygwin/usr/local/openxdk/i386-pc-xbox/include"  -I"C:/cygwin/usr/local/openxdk/include"  -I"C:/cygwin/usr/local/openxdk/include/SDL"
BIN  = Cher.exe
CXXFLAGS = $(CXXINCS)    -c -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM -w
CFLAGS = $(INCS)    -c -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM -w
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before Cher.exe all-after


clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o "Cher.exe" $(LIBS)

Joystick.o: Joystick.c
$(CC) -c Joystick.c -o Joystick.o $(CFLAGS)

SDL_graphics.o: SDL_graphics.c
$(CC) -c SDL_graphics.c -o SDL_graphics.o $(CFLAGS)

Settings.o: Settings.cpp
$(CC) -c Settings.cpp -o Settings.o $(CFLAGS)

Error.o: Error.c
$(CC) -c Error.c -o Error.o $(CFLAGS)

Cher.o: Cher.cpp
$(CC) -c Cher.cpp -o Cher.o $(CFLAGS)

Menu.o: Menu.cpp
$(CC) -c Menu.cpp -o Menu.o $(CFLAGS)

Cher_private.res: Cher_private.rc
$(WINDRES) -i Cher_private.rc --input-format=rc -o Cher_private.res -O coff
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
kennelbound
post May 22 2005, 07:59 PM
Post #2


X-S Member
*

Group: Members
Posts: 63
Joined: 13-August 03
Member No.: 55925



Here's another tool (for uploading the default.xbe to the server)

1) On the xbox, ensure that you have a folder to install to (i.e. F:\Apps\Cher)
2) Startup notepad, and paste the following into it:
CODE
@echo off
>  C:\script.txt echo open %1
>> C:\script.txt echo xbox
>> C:\script.txt echo xbox
>> C:\script.txt echo cd /F/Apps/%2
>> C:\script.txt echo binary
>> C:\script.txt echo put default.xbe
>> C:\script.txt echo bye
start /w %windir%\System32\ftp.exe -s:C:\script.txt
del C:\script.txt
cls
exit


[B]Note: For Win95/98/ME users, you may need to change start /w %windir%\System32\ftp.exe -s:C:\script.txt to start /w %windir%\ftp.exe -s:C:\script.txt
3) Click File->Save As
4) Change the Save as Filetype to All Files
5) Browse to C:\cygwin\usr\local\openxdk\bin
6) Save as "ftp2xbox.bat" (include quotes)
7) Startup Bloodshed C++ and load your project
8) Click Tools->Configure Tools
9) Click on the Plus to add a new tool
10)Name the tool FTP2XBOX
11)In the Program box put "C:\cygwin\usr\local\openxdk\bin\ftp2xbox.bat" (without quotes)
12)In the working directory box put "<PROJECTPATH>" (without quotes)
13)In the Parameters box put "#XBOX# <PROJECTNAME>" (without quotes) where #XBOX# is the xbox's ip address
14)Click OK
15)Click Close
16)Recompile the files (CTRL-F11)
17)Click Tools->FTP2XBOX
18)A window will popup temporarily then disappear

That's it. You have to upload any other important files, but this simplifies the entire testing process.

This script is adapted from the tutorial at http://www.ericphelps.com/batch/samples/ftp.script.txt.

This post has been edited by kennelbound: May 22 2005, 08:00 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
kennelbound
post May 22 2005, 08:20 PM
Post #3


X-S Member
*

Group: Members
Posts: 63
Joined: 13-August 03
Member No.: 55925



Someone has brought to my attention that this only works if you are running BSC++ from within Cygwin.

To run outside of cygwin do the following:

1) Startup BSC++ (from within cygwin)
2) Click Tools->Compiler Options
3) Click on the Directories tab
4) In the bottom box put "C:\cygwin\bin" (without the quotes) and then click Add
5) Click OK
6) Close BSC++ and Cygwin
7) Launch BSC++ (from outside of cygwin)
8) Load your project and recompile (using CTRL-F11)

This should allow you to compile without loading cygwin
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SmashManiac
post Jun 10 2005, 02:33 AM
Post #4


X-S Young Member
*

Group: Members
Posts: 59
Joined: 4-May 05
Member No.: 218562
Xbox Version: v1.2
360 version: none



Looking good, but I can't get it to work. I have Dev-C++ v.4.9.8.0, and here are my conclusions...

First, small mistake: Step 13 of "setting up the IDE" is incorrect. The correct name of the tab is Programs.

Finally, it doesn't work anyway, even with an empty code. Here is my log:

-----
Compiler: Xbox
Building Makefile: "C:\Documents and Settings\fortindg\Bureau\test\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\fortindg\Bureau\test\Makefile.win" all
g++.exe i386-pc-xbox-g++ -c main.cpp -o main.o -I"C:/Program Files/Dev-Cpp/include/c++" -I"C:/Program Files/Dev-Cpp/include/c++/mingw32" -I"C:/Program Files/Dev-Cpp/include/c++/backward" -I"C:/Program Files/Dev-Cpp/include" -I"R:/openxdk/i386-pc-xbox/include" -I"R:/openxdk/include" -I"R:/openxdk/include/SDL" -c -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM

g++.exe: cannot specify -o with -c or -S and multiple compilations

make.exe: *** [main.o] Error 1

Execution terminated
-----

Unless those problems are solved in your v.4.9.9.2, this tutorial doesn't work at all because of all of the added erroneous parameters. Which ones? I have no idea, since it's the first time I'm using OpenXDK.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
d0wnlab
post Jun 10 2005, 05:06 PM
Post #5


X-S Expert
***

Group: Moderator
Posts: 557
Joined: 22-November 03
Member No.: 76129
Xbox Version: unk



QUOTE(SmashManiac @ Jun 10 2005, 03:44 AM)

g++.exe i386-pc-xbox-g++ -c main.cpp -o main.o -I"C:/Program Files/Dev-Cpp/include/c++" 
*



your problem is right at the start of the line. It thinks the name of the compiler is "g++.exe i386-pc-xbox-g++". It should be just the latter part, the "i386-pc-xbox-g++". You might need the '.exe' at the end of that, I'm not sure. This is from a discrepancy from step 14 and 15, which read:

QUOTE
14)Next to gcc put "i386-pc-xbox-gcc" (without the quotes)
15)Next to g++ put "i386-pc-xbox-g++" (without the quotes)


I think kennelbound means to say something like "replace gcc.exe with 'i386-pc-xbox-gcc'" and similiarily for g++.

This is just an educated guess, try changing that and let us know how it goes..
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
kennelbound
post Jun 12 2005, 06:07 AM
Post #6


X-S Member
*

Group: Members
Posts: 63
Joined: 13-August 03
Member No.: 55925



I apologize for the errors.

Yes, when I put 'next to gcc' I meant next to the field titled gcc, and similarly with g++.

As for the tab name, well... oops!

Sorry if that wasn't more clear. Has anybody else had success or failure with this? Any more mistakes? Let's fix it now if there are.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
kennelbound
post Jun 14 2005, 06:39 PM
Post #7


X-S Member
*

Group: Members
Posts: 63
Joined: 13-August 03
Member No.: 55925



Just set this up on another computer, with no problems.

In my version (4.9.9.2) of BSC++ the tab on step 13 is entitled Binaries.

It is compiling my C++ app just fine.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
d0wnlab
post Jun 14 2005, 06:43 PM
Post #8


X-S Expert
***

Group: Moderator
Posts: 557
Joined: 22-November 03
Member No.: 76129
Xbox Version: unk



cool!

Has anyone tested using extensive c++ features? I'm using a mingw32 port for linux and I haven't pinned it down, but in general applications using things like assert, RTTI, or templates end up with a large list of unresolved symbols originating in libstdc++. Anyone experiencing similiar things?

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Carcharius
post Jun 14 2005, 07:24 PM
Post #9


X-S Expert
***

Group: Members
Posts: 630
Joined: 11-May 03
Member No.: 37299



Yep I've had similar results with stuff like that.

Makes it next to useless for what I want to do.

Nevermind - developments are underway.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SmashManiac
post Jun 15 2005, 06:42 PM
Post #10


X-S Young Member
*

Group: Members
Posts: 59
Joined: 4-May 05
Member No.: 218562
Xbox Version: v1.2
360 version: none



Seems that your troubleshooting still doesn't apply for me. I've taken some screenshots to show you.

After step 12:
user posted image

After step 13:
user posted image

Now I'm trying to do step 14... but the only thing showing about some kind of "gcc" anywhere on the screen is at the middle of the directory name! Even worse for step 15, since there's absolutely no reference on the screen for "g++"! Idem for step 16 with "windres"!

So I thought that maybe there's an error there, maybe I'm just not in the correct section. I checked all the tabs, and the only tab containing all of the strings were the "Programs" tab. If going there and apply step 14 to 16:
user posted image

Looked ok, until I tried to compile. Anybody have a clue?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
d0wnlab
post Jun 15 2005, 07:30 PM
Post #11


X-S Expert
***

Group: Moderator
Posts: 557
Joined: 22-November 03
Member No.: 76129
Xbox Version: unk



look at that last picture again. Remove the 'gcc.exe' and the 'g++.exe' so all that is left in those two text boxes are "i386-pc-xbox-gcc" and "i386-pc-g++", respectively.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SmashManiac
post Jun 16 2005, 07:56 PM
Post #12


X-S Young Member
*

Group: Members
Posts: 59
Joined: 4-May 05
Member No.: 218562
Xbox Version: v1.2
360 version: none



QUOTE(d0wnlab @ Jun 15 2005, 03:41 PM)
look at that last picture again.  Remove the 'gcc.exe' and the 'g++.exe' so all that is left in those two text boxes are "i386-pc-xbox-gcc" and "i386-pc-g++", respectively.
*



When I do that, Windows XP returns an error message that says that 'i386-pc-xbox-g++' is not a valid command or filename, which is true. That can't be it, or it won't find the compilers!!!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
d0wnlab
post Jun 16 2005, 07:59 PM
Post #13


X-S Expert
***

Group: Moderator
Posts: 557
Joined: 22-November 03
Member No.: 76129
Xbox Version: unk



make it "i386-pc-xbox-gcc.exe" and "i386-pc-xbox-g++.exe" then? If that doesn't work then your PATH is set up wrong.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
kennelbound
post Jun 16 2005, 09:39 PM
Post #14


X-S Member
*

Group: Members
Posts: 63
Joined: 13-August 03
Member No.: 55925



Under the Directories tab, do you see the Binaries sub-tab?

This is the directories where your binaries are stored.

You have to add c:\cygwin\usr\local\openxdk\bin to this list, preferably at the top.

This should resolve the issue for you.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SmashManiac
post Jun 19 2005, 04:34 PM
Post #15


X-S Young Member
*

Group: Members
Posts: 59
Joined: 4-May 05
Member No.: 218562
Xbox Version: v1.2
360 version: none



ohmy.gif Oh no, I think I understand the other problem now!

The fact is that I cannot install OpenXDK in my cygwin directory, because my C: is blocked by my administrator. I can only install in the R: partition. Is it possible to configure OpenXDK like that?

I would like to install cygwin at home, but my computer won't take it for some reason...
User is offlineProfile CardPM
Go to the top of the page
+Quote Post





2 Pages V  1 2 >
Reply to this topicStart new topic

 

Lo-Fi Version Time is now: 6th September 2010 - 01:58 AM