xboxscene.org forums

Pages: [1] 2

Author Topic: Using C++ With Openxdk  (Read 215 times)

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« on: May 22, 2005, 12:06:00 PM »

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:"" -DUMPINFO:".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
#include
#include
#include "Joystick.h"
#include "SDL_graphics.h"
#include
}
#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
Logged

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« Reply #1 on: May 22, 2005, 12:59:00 PM »

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

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« Reply #2 on: May 22, 2005, 01:20:00 PM »

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
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
Using C++ With Openxdk
« Reply #3 on: June 10, 2005, 10:06:00 AM »

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

Logged

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« Reply #4 on: June 11, 2005, 11:07:00 PM »

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.
Logged

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« Reply #5 on: June 14, 2005, 11:39:00 AM »

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.
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
Using C++ With Openxdk
« Reply #6 on: June 14, 2005, 11:43:00 AM »

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?

Logged

Carcharius

  • Archived User
  • Sr. Member
  • *
  • Posts: 304
Using C++ With Openxdk
« Reply #7 on: June 14, 2005, 12:24:00 PM »

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.
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
Using C++ With Openxdk
« Reply #8 on: June 15, 2005, 12:30:00 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.
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
Using C++ With Openxdk
« Reply #9 on: June 16, 2005, 12:59:00 PM »

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.
Logged

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« Reply #10 on: June 16, 2005, 02:39:00 PM »

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.
Logged

SmashManiac

  • Archived User
  • Newbie
  • *
  • Posts: 11
Using C++ With Openxdk
« Reply #11 on: June 19, 2005, 09:34:00 AM »

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...
Logged

kennelbound

  • Archived User
  • Newbie
  • *
  • Posts: 39
Using C++ With Openxdk
« Reply #12 on: June 22, 2005, 11:02:00 AM »

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
Logged

d0wnlab

  • Archived User
  • Sr. Member
  • *
  • Posts: 326
Using C++ With Openxdk
« Reply #13 on: July 22, 2005, 08:06:00 AM »

ColdReader:

see if this thread helps you out:

http://forums.xbox-s...howtopic=412675
Logged

Sirmatto

  • Archived User
  • Full Member
  • *
  • Posts: 134
Using C++ With Openxdk
« Reply #14 on: August 30, 2007, 07:13:00 AM »

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.
Logged
Pages: [1] 2