Несколько файлов подписывают неопределенную ссылку - extern

У меня относительно большой проект, и я использую тот же синтаксис, что и в предыдущей версии проекта, где он работал нормально.

в файле 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);
}

в файле Note.h

extern std::ofstream *notaFile;

в файле Note.cpp

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

void Note::setPitchWellTempered(int absPitchNum) {

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

при связывании:

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

0 ответов

Другие вопросы по тегам