c++ and assembly: undefined reference to

Hi!
I'm writing a little equation solver for an exam ... it has not to be perfect or mathematically rigorous. With this program I have only to show to my professor that I can write some simple program in Assembly and C++ language. In other words, I have only to show if I have understood the basis of Assembly language. I'm referring to x86 Assembly Language.
Here's the source code: there are some c++ classes and assembly functions:

(I cannot post all the source code because it's too long for the posting form, I'm uploading it to my dropbox folder, please download it).

FILE 1: http://dl.dropbox.com/u/3371514/class_razionali_debug.cpp
FILE 2: http://dl.dropbox.com/u/3371514/equa.s
FILE 3: http://dl.dropbox.com/u/3371514/rad.cpp

It's obvious that this source cod isn't complete (I'm going to finish it during the next days) but it should compile. It doesn't. I'm under linux (ubuntu) and I'm trying to compile it using these commands:

g++ -c -o equa_s.o equa.s -g3 -m32
g++ -c -o rad.o rad.cpp -g3 -m32
g++ -c -o equa_c.o class_razionali_debug.cpp -g3 -m32
g++ -o equa.out equa_s.o equa_c.o rad.o -g3 -m32

But when I try to link all the object files I get this error message:
equa_s.o: In function `second_grade_comp_solver':
/home/gianx80/Documenti/equa.s:81: undefined reference to `rad'


So, how can I compile my program without errors?
I'm only guessing here, as I have never done anything that awesome before, but would you have to use extern "C" to supress C++ name mangling? I would [ignorantly?] expect the assembly code to be compiled into a C object file.

Here's a little information regarding calling a C++ function from C, for reference:
http://www2.research.att.com/~bs/bs_faq2.html#callCpp

Actually, why is the extern line for rad in class_razionali_debug.cpp and not in rad.cpp?
Last edited on
Yes, I think you are right (without looking at the source). rad() would need to be
declared extern "C" otherwise the name will be mangled.
In which file I have to declare extern the rad function? In the assembly file? I've already tried to add this line to equa.s but I get the same error

.extern rad

P.S.
Actually, why is the extern line for rad in class_razionali_debug.cpp and not in rad.cpp?

It was only a stupid try xD
In the C++ source.
I added this line to class_razionali_debug.cpp

extern "C" int rad (const int num);

I get the same error.

EDIT

I solved the problem. I used the extern "C" and merged the rad.cpp file with the class_razionali_debug.cpp file.
If I mantain the three files organization, the source code won't link. Why?
Last edited on
Topic archived. No new replies allowed.