Question

This question is not new, but I honestly have no idea what I'm doing wrong here. The program is supposed to take an expression, modify it, call some assembly code and then show the result, but somehow, after including the analyse.h file containing the required analysis functions, the main seems to have problems accessing the said functions.

What am I supposed to do in addition to writing #include "analyse.h"?

(Also, the "Analyse" part is not mine and I can't modify it. I can only modify the main.)

Thank you in advance!

Errors:

undefined reference to `shuntingYard(char*, char*, int)'
undefined reference to `makeTree(char*)'
undefined reference to `deleteTree(Noeud*)'

Main:

#include <iostream>

#include "analyse.h"

using namespace std;

int main()
{
    char entry[500];
    char* pEntry = entry;
    char polonaise[1000];
    char* pPolonaise = polonaise;
Noeud* root;

string rawEntry;

//read expression

cin >> rawEntry;

for(size_t i = 0; i < rawEntry.size() ; i++)
    entry[i] = rawEntry[i];

//convert tree

shuntingYard(pEntry, pPolonaise, rawEntry.size());

root = makeTry(pPolonaise);

//* ... */

deleteTry(root);

return 0;

}

Analyse.h:

#ifndef ANALYSE_H
#define ANALYSE_H

#include <stdio.h>
#include <string.h>
#include <stack>

#define TYPE_NOMBRE 0
#define TYPE_OPERATEUR 1
#define TYPE_VARIABLE 2

using namespace std;

struct Noeud
{
 int type;
 int valeur;
 Noeud* gauche;
 Noeud* droite; 
};
/* ... */
void shuntingYard(char *,char*, int);

/* ... */
Noeud* makeTree(char *);

/* ... */
void deleteTree(Noeud*);

#endif
Was it helpful?

Solution

You need to link the code (or the library) that contains the implementation.

If you were given the source code for the implementation (analyse.cpp) then you can compile and link it into your executable.

If you were given a shared object / dll for the implementation, then you will need to link with the .so / .lib.

If you were given a static library then you will need to link with the .a / .lib.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top