Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined references when linking assembly and C++ using g++
    primarykey
    data
    text
    <p>I have to write some member functions of a class in Assembly for an exam. I've followed every instruction but I still can't get it to work. Here are the relevant files. The header and the main method are already provided, I just need to write the constructor and the <code>elab1</code> method.</p> <p><strong>Class header</strong></p> <pre><code>#include &lt;iostream&gt; using namespace std; struct st { int a; int vv1[4]; double vv2[4]; }; class cl { double b; st s; public: cl(int *p, double *d); void elab1(st ss); void stampa() { int i; cout &lt;&lt; b &lt;&lt; ' ' &lt;&lt; s.a &lt;&lt; endl; for (i=0;i&lt;4;i++) cout &lt;&lt; s.vv1[i] &lt;&lt; ' '; cout &lt;&lt; '\t'; for (i=0;i&lt;4;i++) cout &lt;&lt; s.vv2[i] &lt;&lt; ' '; cout &lt;&lt; endl; cout &lt;&lt; endl; } }; </code></pre> <p><strong>Main method for testing</strong></p> <pre><code>// prova1.cpp #include "cc.h" // class header int main() { st s = {1, 1,2,3,4, 1,2,3,4 }; int v[4] = {10,11,12,13 }; double d[4] = { 2, 3, 4, 5 }; cl cc1(v, d); cc1.stampa(); cc1.elab1(s); cc1.stampa(); } </code></pre> <p>And this is my <strong>assembly</strong>:</p> <pre><code># es1.s .text .global __ZN2clC1EPiPe __ZN2clC1EPiPe: pushl %ebp movl %esp, %ebp subl $4, %esp pushl %eax pushl %ebx pushl %ecx pushl %edx pushl %esi cmpl $0, 12(%ebp) je fine cmpl $0, 16(%ebp) je fine movl 8(%ebp), %eax movl 12(%ebp), %ebx movl 4(%ebx), %ecx movl %ecx, 12(%eax) fldz fstpl (%eax) movl $0, -4(%ebp) ciclo: cmpl $4, -4(%ebp) je fine movl -4(%ebp), %esi movl 12(%ebp), %ebx movl (%ebx, %esi, 4), %ecx subl %esi, %ecx movl %ecx, 16(%eax, %esi, 4) movl 16(%ebp), %ebx pushl %eax movl %esi, %eax movl $3, %ecx imull %ecx movl %eax, %edx popl %eax movl 12(%ebp), %ecx fldl (%ebx, %edx, 4) fldl (%ecx, %esi, 4) faddp %st, %st(1) fstpl 32(%eax, %edx, 4) fldl (%ebx, %edx, 4) fldl (%eax) faddp %st, %st(1) fstpl (%eax) incl -4(%ebp) jmp ciclo fine: popl %esi popl %edx popl %ecx popl %ebx popl %eax movl 8(%ebp), %eax leave ret .global __ZN2cl5elab1E2st __ZN2cl5elab1E2st: #TODO </code></pre> <p>I try to compile and link everything with the command-line statement that has been provided to us:</p> <pre><code>g++ -o es1 -fno-elide-constructors es1.s prova1.cpp </code></pre> <p>but it only gives me a bunch of <code>undefined reference</code>s:</p> <pre><code>/tmp/ccbwS0uN.o: In function `main': prova1.cpp:(.text+0xee): undefined reference to `cl::cl(int*, double*)' prova1.cpp:(.text+0x192): undefined reference to `cl::elab1(st)' collect2: ld returned 1 exit status </code></pre> <p>Do you have any idea how can I solve this issue? I thought that probably I might have translated the function names in the wrong way, but I've checked them several times.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload