I try to write simple c++ program that calls aarch64 assembly function. But when I try to link it i get this error:
usr/bin/ld: /tmp/ccQFRHpO.o: in function `read_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
main.cpp:(.text+0x1a4): undefined reference to `Distance(int, int, int, int)'
collect2: error: ld returned 1 exit status
I know that this problem was posted many times, but I couldn’t fine solution for my case. There seems to be no mismatch function names.
Commands I run:
as odl.s -o odl.o
g++ main.cpp odl.o -o main
Content of my files:
main.cpp :
#include "functions.h"
using namespace std;
dane *glowa;
int main(int argc, char *argv[]){
if(argc < 2)
return 1;
glowa = read_file("dane/" + string(argv[1]));
return 0;
}
functions.h :
#include<omp.h>
#include<fstream>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
extern double Distance(int a, int b, int c, int d);
struct dane{
double czas;
unsigned char liczba_rdzeni;
double *tablica;
};
dane* read_file(std::string file_name){
dane *glowa = new dane;
glowa->liczba_rdzeni = 1;
std::vector<int> xy;
int a;
std::fstream in;
in.open(file_name, std::ios::in);
while (in>>a)
xy.push_back(a);
in.close();
glowa->tablica = new double[(xy.size()/2)*(xy.size()/2)];
for(int i = 0; i < (xy.size()/2); i += 2)
for(int j = 0; j < (xy.size()/2); j += 2){
if(j == i)
glowa->tablica [i*(xy.size()/2)+j] = 0;
else
glowa->tablica [i*(xy.size()/2)+j] = Distance(xy[i], xy[i+1], xy[j], xy[j+1]);
}
return glowa;
}
odl.s :
global Distance
.section .text
Distance:
add x0, x0, x2
add x1, x1, x3
mul x1, x1, x1
madd x0, x1, x0, x0
scvtf d0, x0
fsqrt d0, d0
ret
New contributor
pl_Olov3 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.