0
У меня проблемы с компоновщиком g ++. Мой код выглядит следующим образом:Ошибка компоновщика C++ OSX Mavericks
prog3.cpp
#include "linkedlist.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
bool readFile(const char* file, linkedlist &l);
int main(int argc, char **argv)
{
int i = 0, j = 0; //Incrementers
linkedlist dictionary;
string word;
ifstream fin;
if(argc != 3)
{
//give the user an error and exit
}
if(!readFile("dictionary_short.txt", dictionary))
{
//give the user an error and exit
}
dictionary.printToCommandline();
return 0;
}
bool readFile(const char* file, linkedlist &l)
{
string tmp;
ifstream fin;
fin.open(file, ios::in);
if(fin.is_open())
{
//Read the file
while(!fin.eof())
{
fin >> tmp;
l.insert(tmp);
}
//close the file and return the array
fin.close();
return true;
}
return false;
}
linkedlist.h
class linkedlist
{
public:
/*!
* @brief Constructor for the linked list
*/
linkedlist();
/*!
* @brief Deconstructor for the linked list
*/
~linkedlist();
/*!
* @brief inserts a word into the linked list. Returns true if sucessful.
*/
bool insert(string str);
/*!
* @brief removes a word from the linked list. Returns true if successful
*/
bool remove(string str);
/*!
* @brief finds a word in the linked list. Returns true if sucessful
*/
bool find(string str);
/*!
* @brief Increases the frequency count of a word. Returns true if sucessful
*/
bool incrementFrequency(string str);
/*!
* @brief Returns true if a node is empty.
*/
bool isEmpty();
/*!
* @brief Returns the manimum frequency of a word from the linked list.
*/
int getMaxFrequency();
/*!
* @brief Returns the number of nodes in the list.
*/
int size();
/*!
* @brief Outputs the list into a file formatted correctly.
*/
void printToFile(ostream &out);
/*!
* @brief Outputs the list to the command line in alphabetical order
*/
void printToCommandline();
private:
/*!
* @brief Structure for a node. Keeps track of the frequency for the word.
* Stores the word. Also keeps a pointer to the next word in the list.
*/
struct node
{
int frequencyCount;
string word;
node *next;
};
node *headptr;
};
linkedlist.cpp
#include "linkedlist.h"
linkedlist::linkedlist()
{
headptr = nullptr;
}
linkedlist::~linkedlist()
{
//Function Implementation
}
bool linkedlist::insert(string str)
{
//Function Implementation
}
bool linkedlist::remove(string str)
{
//Function Implementation
}
bool linkedlist::find(string str)
{
//Function Implementation
}
bool linkedlist::incrementFrequency(string str)
{
//Function Implementation
}
bool linkedlist::isEmpty()
{
//Function Implementation
}
int linkedlist::getMaxFrequency()
{
//Function Implementation
}
int linkedlist::size()
{
//Function Implementation
}
void linkedlist::printToFile(ostream &out)
{
//Function Implementation
}
void linkedlist::printToCommandline()
{
//Function Implementation
}
ошибка я получаю, когда я компилирую (с использованием g ++ в Mac OS X 10.9.2):
Undefined symbols for architecture x86_64:
"linkedlist::printToCommandline()", referenced from:
_main in prog3-717fc0.o
"linkedlist::insert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
readFile(char const*, linkedlist&) in prog3-717fc0.o
"linkedlist::linkedlist()", referenced from:
_main in prog3-717fc0.o
"linkedlist::~linkedlist()", referenced from:
_main in prog3-717fc0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Finished in 0.3s with exit code 1]
Просто из любопытства я скопировал файлы в проект Xcode, и у меня не было никаких ошибок. Как я могу исправить эту проблему с компоновщиком?
Спасибо! Это сработало. Есть ли способ, которым я могу заставить g ++ делать это для меня одной командой? – ellman121