在linux mint中使用NetBeans IDE進行C++編程。 NetBeans的編譯代碼就好了,但是當我嘗試使用G ++編譯main.cpp
在g++ main.cpp
我得到undefined reference
錯誤:g ++錯誤:netbeans在linux編譯時未定義的引用
我知道有這樣一個很多問題,他們的問題可以通過使用正確的-l固定庫,但我找不到任何與NetBeans/g ++相關的東西,我無法解決如何解決這個問題。 任何幫助表示讚賞。
錯誤:
tmp/ccXSo5xI.o: In function `main':
main.cpp:(.text+0x82): undefined reference to `Hospital::Hospital(int, int, int)'
main.cpp:(.text+0xf3): undefined reference to `Resident::Resident(int, int)'
.
.
.
的main.cpp
#include <iostream>
#include <cstdio>
#include "Resident.h"
#include "Hospital.h"
#include <stack>
using namespace std;
void readFromFiles(int [][10], int [][10]);
void readFromFiles(Hospital*[10], Resident*[10]);
void print10(int [][10], int [][10]);
void print10(Hospital*[10], Resident*[10]);
int main(void) {
int hospital[10][10] = {0};
int resident[10][10] = {0};
Hospital **hospitals = new Hospital*[10];
for(int i = 0 ; i < 10 ; i++)
hospitals[i] = new Hospital(3, i, 10); //3: quota, i: hospital number, 10:prefereneceLength
Resident **residents = new Resident*[10];
for(int i = 0 ; i < 10 ; i++)
residents[i] = new Resident(i,10); //i: hospital number, 10:prefereneceLength
.
.
.
Hospital.h
#ifndef HOSPITAL_H
#define HOSPITAL_H
#include "Resident.h"
using namespace std;
class Hospital {
public:
//constructors & destructors
Hospital();
Hospital(const int, const int, const int);
Hospital(const Hospital& orig);
virtual ~Hospital();
//getters & setters
int getNumber();
int getQuota();
int** getPreferenceList();
//member functions
void addPreference(const int, const int);
private:
int number;
int* preferenceList[2]; //1st row: preference order ; 2nd row: admission status
int quota;
Resident *admittedResidents;
};
#endif /* HOSPITAL_H */
Resident.h
#ifndef RESIDENT_H
#define RESIDENT_H
class Resident {
public:
//constructors & destructors
Resident();
Resident(const int, const int);
Resident(const Resident& orig);
virtual ~Resident();
//getters, setters
int getNumber();
int* getPreferenceList();
bool getAdmissionStatus();
//member functions
void addPreference(const int, const int);
private:
int number; //resident number
int proposalCount;
int* preferenceList; //not inverse, unlike Hospitals pref list
bool admissionStatus;
};
#endif /* RESIDENT_H */
即使縮短了代碼,我也知道很多代碼,但我認爲它們是必要的部分。謝謝。
相關:http://stackoverflow.com/q/15441877/78845 – Johnsyweb 2013-03-17 21:50:17