0

I have a relatively large project and I am using the same syntax as in a previous version of the project where it worked fine.

in file Main.cpp:

#include "Note.h"

#include <iostream>
#include <fstream>
using namespace std;

std::ofstream  *notaFile;
int main(int parameterCount, char **parameterList) {
  notaFile = new std::ofstream("Notation.txt", ios::out);
}

in file Note.h

extern std::ofstream *notaFile;

in file Note.cpp

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void Note::setPitchWellTempered(int absPitchNum) {

   *notaFile << "Octave Number " << octaveNum << endl;
}

when linking:

lib/liblcmod.a(Note.o): In function `Note::setPitchWellTempered(int)':
CMOD/src/Note.cpp:117: undefined reference to `notaFile'
collect2: ld returned 1 exit status
Praetorian
  • 106,671
  • 19
  • 240
  • 328
Artaud
  • 1
  • 1
  • Probably more information you'll actually need, but I'm sure you'll find your answer in the duplicate. – πάντα ῥεῖ Aug 01 '16 at 19:31
  • This might be actually kinda tricky, if the Note.cpp is part of a static library linked to Main.cpp later. Because to actually satisfy the notaFile external it might be necessary that the Main.o appears on the command line after the liblcmod.a. I would in general prefer to move the notaFile declaration to Note.cpp, i.e. into the library. – EmDroid Aug 01 '16 at 21:20

0 Answers0