0

I've been beating my head against this for too long now, and have researched everything I cannot find what's wrong.

I'm writing a GUI program in QT and have a few functions in some files external to the main program file, but within the project. The structure is something like this:

Source files: 
main.cpp 
mainwindow.cpp
signal.cpp
signalparse.cpp

header files: 
mainwindow.h
signal.h
signalparse.h

Signal is an object that stores some data. Signalparse uses signal, parses a text file and reads it into signal. I tested this functionality on a barebones console application before putting it into my GUI program so I know it works(worked).

Now I find myself trying to call a function ReturnSignal from my SignalParse.cpp file inside my mainwindow.cpp file.

SignalParse.h is below:
#include<vector>
#include <iostream>
#include "signal.h"

void ParseLine(std::string*);
std::string ReturnTitle();
std::vector<Signal> ReturnSignal(std::string);

Showing I have declared ReturnSignal.

Inside SignalParse.cpp the function is defined as:

vector<Signal> ReturnSignal(string filename)
{
    //does stuff
}

Inside mainwindow.cpp I declare an

std::vector<Signal> signalList;

to store the returned vector from ReturnSignal.

I then use

signalList = ReturnSignal(signalFilePath);

inside mainwindow.cpp to finally call this function and return my data. When commented out, there are no errors. However, this line causes the error:

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class std::vector<class Signal,class std::allocator<class Signal> > __cdecl ReturnSignal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ReturnSignal@@YA?AV?$vector@VSignal@@V?$allocator@VSignal@@@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) referenced in function "private: void __cdecl MainWindow::on_file_open_triggered(void)" (?on_file_open_triggered@MainWindow@@AEAAXXZ)

I cannot for the life of me figure out why this wont work. Does anyone have any ideas? I've been looking for hours now! I would love to re-write the question to be more generally applicable if i find a solution, but at the moment I'm completely stumped. Thanks a lot.

EDIT: Compiler being used is Microsoft Visual C++ Compiler 12.0

George G
  • 61
  • 1
  • 8
  • What compiler are you using? What are you telling it / the makefile? – Ivan Rubinson Jan 09 '17 at 15:08
  • I'm using the compiler within QtCreator. It has a .pro file that defines which files are included. – George G Jan 09 '17 at 15:10
  • It's possible that your compiler isn't given the source files to compile, or your linker isn't given the intermediary binary files that the compiler generates. – Ivan Rubinson Jan 09 '17 at 15:15
  • As far as I can tell the compiler knows about the cpp and h files. I'm not sure about the bin files. As far as I know, I can't change much else within QT about it. – George G Jan 09 '17 at 15:19
  • You said you tried the code in a different project (a console app). How did you move it to the Qt project? – Ivan Rubinson Jan 09 '17 at 15:21
  • I originally coded it in visual studio, and had a console app spit out some cout lines. I recoded it slightly to remove the outputs and then put the code into QT directly. – George G Jan 09 '17 at 15:28
  • So you copy-pasted the source files in to the Qt project's directory? – Ivan Rubinson Jan 09 '17 at 15:29
  • 1
    I added empty files to the project and put the code directly into the new file. – George G Jan 09 '17 at 15:31
  • Please paste us the linker command that is executed that leads to this error (see Compile Output pane) – E4z9 Jan 09 '17 at 19:01
  • http://pastebin.com/5Tk0d7c9 Entire compiler output is here. – George G Jan 10 '17 at 00:55

1 Answers1

0

After some serious headaches I found a very simple solution. Having only really used either command line compilers or Visual Studio, this did not occur to me.

It turns out that in order to fix most of the unresolved external errors I was dealing with, I had to simply go into the build menu, clean my project and then "Run qmake". After this, all my unresolved externals disappeared and my program worked.

I don't know why it was so hard for me to find this information, hopefully it will be of help to someone in a similar spot.

George G
  • 61
  • 1
  • 8