Help - Search - Members - Calendar
Full Version: Using C++ With Openxdk
Scenyx Entertainment Community > Xbox1 Forums > Software Forums > Development
kennelbound
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
kennelbound
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.
kennelbound
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
SmashManiac
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.
d0wnlab
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..
kennelbound
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.
kennelbound
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.
d0wnlab
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?

Carcharius
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.
SmashManiac
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?
d0wnlab
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.
SmashManiac
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!!!
d0wnlab
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.
kennelbound
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.
SmashManiac
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...
kennelbound
It should work just fine. Just replace any instance of C: with R:.

Although, cygwin does write to the registry, so you may have some trouble unless they give you write access to HKLM\Software\Cygnus Solutions
ColdReader
im having a problem compiling i followed all the steps heres the build log

Compiler: Xbox
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
i386-pc-xbox-g++.exe -c ../openxdk/openxdk/samples/comingSoon.c -o ../openxdk/openxdk/samples/comingSoon.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/openxdk/openxdk/include" -I"C:/openxdk/openxdk/i386-pc-xbox/include" -I"C:/openxdk/openxdk/include/SDL" -c -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM

'i386-pc-xbox-g++.exe' is not recognized as an internal or external command,
operable program or batch file.

make.exe: *** [../openxdk/openxdk/samples/comingSoon.o] Error 1

Execution terminated



heres the source


extern "C" {
#include "comingSoon.h"
#include <hal/xbox.h>
#include <hal/video.h>
#include <xboxkrnl/xboxkrnl.h>
}

extern "C" void XBoxStartup(){
{
int *frame_buffer = (int*)XVideoGetFB();

// ******************************************************************
// * clear to black
// ******************************************************************
{
for(int c=0;c<640*480;c++)
frame_buffer[c] = 255;
}

// ******************************************************************
// * render coming_soon image, centered
// ******************************************************************
{
for(int y=220, r=0;y<260;y++)
{
for(int x=160;x<480;x++,r++)
{
int v = y*640+x;
frame_buffer[v] = coming_soon[r] | (coming_soon[r] << 8) | (coming_soon[r] << 16) | (0xFF << 24);
}
}
}
XSleep(5000);
XReboot();
}




also my openxdk directory is c:\openxdk\openxdk\
d0wnlab
ColdReader:

see if this thread helps you out:

http://forums.xbox-scene.com/index.php?showtopic=412675
Alistair23
I have done what your tuturial says but i get this.

CODE
Compiler: Xbox
Building Makefile: "C:\Documents and Settings\Alistair\Desktop\test\Makefile.win"
Executing  make clean
rm -f main.o  default.exe

i386-pc-xbox-g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"  -I"C:/cygwin/usr/local/openxdk/include"  -I"C:/cygwin/usr/local/openxdk/i386-pc-xbox/include"  -I"C:/cygwin/usr/local/openxdk/include/SDL"    -c -g -std=gnu99 -ffreestanding -nostdlib -fno-builtin -fno-exceptions -mno-cygwin -march=i386 -DENABLE_XBOX -DDISABLE_CDROM

'i386-pc-xbox-g++.exe' is not recognized as an internal or external command,
operable program or batch file.

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

Execution terminated


Can someone help me?
Sirmatto
Don't reply to three old topics with something that can asked in one new question. People will tend to ignore you. Google Cygwin and you'll be golden.
davisr
I have successfully compiled my openxdk app, however, I can't run CXBE from inside Dev-C++. I can make xbe files if I manually run a cxbe command from the cygwin bash shell. Is there a solution to this problem?
davisr
QUOTE(davisr @ Jun 23 2008, 12:29 PM) *

I have successfully compiled my openxdk app, however, I can't run CXBE from inside Dev-C++. I can make xbe files if I manually run a cxbe command from the cygwin bash shell. Is there a solution to this problem?


I discovered the problem. My EXE file that was created when it was compiled wasn't named default.exe.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.