I got this error message when I tried to compile my code:
c++ -Ofast -march=native -DNDEBUG -std=c++11 -Wc++11-extensions -Wall matvec.o amath483.o Vector.o -o matvec matvec.o: In function main': matvec.cpp:(.text+0x209): undefined reference to
readVector(std::__cxx11::basic_string, std::allocator >)' clang: error: linker command failed with exit code 1 (use -v to see invocation) makefile:5: recipe for target 'matvec' failed make: *** [matvec] Error 1
My code is as follows:
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <fstream>
#include "Vector.hpp"
using namespace std;
Vector readVector(istream& input) {
string string_input;
int n;
getline(input,string_input);
if(string_input.compare("AMATH 583 VECTOR") != 0) exit(-1);
input >> n;
Vector v(n);
for(int i = 0; i < n; i++)
input >> v(i);
getline(input,string_input);
getline(input,string_input);
if(string_input.compare("THIS IS THE END") != 0) exit(-1);
return v;
}
Vector readVector(ifstream& file) {
string string_input;
int n;
getline(file,string_input);
if(string_input.compare("AMATH 583 VECTOR") != 0) exit(-1);
file >> n;
Vector v(n);
for(int i = 0; i < n; i++)
file >> v(i);
getline(file,string_input);
getline(file,string_input);
if(string_input.compare("THIS IS THE END") != 0) exit(-1);
return v;
}
#include "Vector.hpp"
#include <iostream>
#include <fstream>
#include "amath483.hpp"
using namespace std;
int main(int argc, char* argv[]) {
if(argc < 2 || argc > 4) {
cout << "You must provide at least one argument or at most three arguments(including two options)" << endl;
return -1;
}
int inputoption = -1;
int outputoption = -1;
if(argc == 3) {
inputoption = 0;
}
if(argc == 4) {
inputoption = 0;
outputoption = 0;
}
// Check the format
Vector v = NULL;
if(inputoption == 0) {
string inputfile = argv[2];
v = readVector(inputfile);
} else {
v = readVector(cin);
}
for(int i=0; i < v.numRows(); i++)
cout << v(i) << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire