forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[in-charge] [not-in-charge] problems linking C++ files

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Fri May 02, 2008 10:13 am    Post subject: [in-charge] [not-in-charge] problems linking C++ files Reply with quote

Hey guys. I'm having a problem with compiling code. I have browsed the threads about compiling, but most of them are two to three years old and don't really supply much help. I have had no problems getting C code to compile and link, but I am having major problems getting C++ code to link. I have messed around with the Makefiles and gotten it to the point where I have hit a brick wall. It appears that the compiler recognizes the classes, but when a call is made to their functions, it doesn't like it and gives me this error.

Code:

ee-gcc -mno-crt0 -T/usr/local/ps2dev/ps2sdk/ee/startup/linkfile -L/usr/local/ps2dev/ps2sdk/ee/lib  \
                -o pclis.elf /usr/local/ps2dev/ps2sdk/ee/startup/crt0.o linked_list.o tokenizer.o shell.o pclis.o -lkbd -ldebug -lstdc++ -lc -lkernel
shell.o(.text+0x10): In function `Shell::Shell[not-in-charge]()':
shell.cc: undefined reference to `Tokenizer::Tokenizer[in-charge]()'
shell.o(.text+0x64):shell.cc: undefined reference to `Tokenizer::~Tokenizer [in-charge]()'
shell.o(.text+0x88): In function `Shell::Shell[in-charge]()':
shell.cc: undefined reference to `Tokenizer::Tokenizer[in-charge]()'
shell.o(.text+0xdc):shell.cc: undefined reference to `Tokenizer::~Tokenizer [in-charge]()'
shell.o(.text+0x10c): In function `Shell::~Shell [not-in-charge]()':
shell.cc: undefined reference to `Tokenizer::~Tokenizer [in-charge]()'
shell.o(.text+0x144): In function `Shell::~Shell [in-charge]()':
shell.cc: undefined reference to `Tokenizer::~Tokenizer [in-charge]()'
collect2: ld returned 1 exit status
make: *** [pclis.elf] Error 1


So what is up with the whole "[in-charge]" "[not-in-charge]" thing??? I did some Google searches, but they all came back saying something like "you probably have a linking error" which I already know. How can I fix this? If you want to see my makefile:

MAKEFILE
Code:

EE_BIN = pclis.elf
EE_OBJS = linked_list.o tokenizer.o shell.o pclis.o
EE_LIBS = -lkbd -ldebug -lstdc++

all: $(EE_BIN)

clean:
   rm -f *.o *.elf *.a

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal

_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------


Last edited by whatisdot on Sat May 03, 2008 8:07 am; edited 1 time in total
Back to top
View user's profile Send private message
ragnarok2040



Joined: 09 Aug 2006
Posts: 230

PostPosted: Fri May 02, 2008 2:24 pm    Post subject: Reply with quote

You could try using Makefile.eeglobal_cpp which uses the g++ compiler as well as the appropriate CPPFLAGS and libraries as well as compiling and linking rules. The in-charge/not-in-charge messages are from a __in_chrg parameter passed to objects for exception handling so they point to another object instead of being allocated on the heap when they're thrown, I think. At least that's what I gleaned from my google search :D.
Back to top
View user's profile Send private message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Sat May 03, 2008 5:53 am    Post subject: Reply with quote

Everything appears to compile correctly when I make an ERL... I tried using the different CPP options in the Makefiles, but I can't get the darn thing to make an ELF. From the examples, I can only see C++ being used with ERL files...
Maybe I'm asking the wrong question. Is it even possible to code in C++ and compile an ELF file from it? I haven't seen any simple examples of it.
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Sat May 03, 2008 6:48 am    Post subject: Reply with quote

Simple C++ sample

Makefile
Code:
EE_BIN = main.elf

EE_OBJS = main.o

all: $(EE_BIN)

clean:
   rm -f $(EE_BIN) $(EE_OBJS)

run: all
   ps2client execee host:$(EE_BIN)

reset:
   ps2client reset

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal_cpp


main.cpp

Code:
#include <stdio.h>

class Hello
{
   public:
      void Print()
      {
         printf("Hello C++");
      }
};

int main()
{
   Hello hello;

   hello.Print();

   return 0;
}

_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Sat May 03, 2008 7:25 am    Post subject: Reply with quote

Lukasz,

You're the man!

=) <thumbs up>

What a difference a file extension makes. Change *.cc to *.cpp and suddenly everything works.

C++ will work as long as all the classes are defined in the same file. I'm now trying to figure out how to link multiple files together...
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group