The problem is likely that when g++ compiles your cpp file, it changes the name of m5_checkpoint so that it's not really m5_checkpoint, it's something like that that has extra information which encodes what the types of the arguments and the return type. That's called name mangling, and all C++ compilers do that. When you wrap a definition in extern "C" { ... }, you're telling the compiler that it shouldn't use C++ rules when figuring out what the real name is, it should use the C rules which leave the name alone. Because the actual m5_checkpoint function is written in assembly (I believe) which also doesn't change the names, that's the one you want.

So wherever you include the header file that defines those functions, you should wrap the #include with extern "C" { ... } so that it uses C rules for the whole file.

extern "C" {
#include "foo.h"
}

Alternatively, you could put extern "C" { ... } in the file itself. To really fix the problem, we'll probably want to do that but also put #if-s around it so only the C++ compiler will see it and not the C compiler which won't understand that syntax.

Gabe

Quoting Shu Wang <[email protected]>:

Hi Ali,

I used a simple program to test. It just print "Hello world" and only one
file: test.cpp. It didn't work.
I just did the same things in the tutorial. So I think I compiled the
m5op_alpha.S and link it.
If I modify the test.cpp to test.c and g++ to gcc. It will work.

I am confused about your last sentence. what do you mean to  resolve that
your wrapping m5op.h with extern "C" { ...... }.

Regards,
Shu.



_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

Reply via email to