私はC++で学校のプロジェクトに取り組んでおり、学校のUNIXサーバーを使用して教授の指示に従ってそれを書いています。コンパイルにはvimとg ++を使用しています。
このプロジェクトは別のプロジェクト Lab0 から構築されており、TA の助けを借りて問題なく構築できましたが、構築するために奇妙なことをしなければなりませんでした (LinkedSortedList.h の下部にある #include LinkedSortedList.cpp ファイルを含める) )。クラスの全員が #include .cpp ファイルでこの奇妙なことをしました。
まず、コンパイルに問題なく動作する Lab0 用のファイルと #includes は次のとおりです。
(投稿は私のメイクファイルに私のタブを表示していませんが、そこにあります!)
メイクファイル:
main: *.cpp *.h
g++ -o LSL main.cpp
clean:
rm -f *.o LSL*
Lab0 (ビルドするもの) は次のようになります。
ファイル:
main.cpp (テンプレート化されていません):
#include "LinkedSortedList.h"
#include <iostream>
using namespace std;
SortedList.h (テンプレート): なし
LinkedNode.h (テンプレート):
#include <iostream>
using namespace std;
LinkedSortedList.h (テンプレート):
#include "SortedList.h"
#include "LinkedNode.h"
#include <iostream>
using namespace std;
#include "LinkedSortedList.cpp" // At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.
LinkedSortedList.cpp (テンプレート): なし
このプロジェクトのビルドと実行に問題はありません。
これが私の問題です:
以下は lab1 で、私が問題を抱えているもので、Lab1 は Lab0 のすべてのファイルを使用し、Employee.h と Employee.cpp を追加するだけです。
Lab1 (ビルドしないもの) は次のようになります。
ファイル:
lab1.cpp:
#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include "Employee.h"
#include "LinkedSortedList.h"
SortedList.h (テンプレート): なし
LinkedNode.h (テンプレート):
#include <iostream>
using namespace std;
LinkedSortedList.h (テンプレート):
#include "SortedList.h"
#include "LinkedNode.h"
#include "Employee.h"
#include <iostream>
using namespace std;
#include "LinkedSortedList.cpp" // At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.
LinkedSortedList.cpp (テンプレート): なし
Employee.h (テンプレート化されていません):
#include <iostream>
#include <sstream>
using namespace std;
Employee.cpp (テンプレート化されていません):
#include <stdio.h>
#include <string.h>
(投稿は私のメイクファイルに私のタブを表示していませんが、そこにあります!)
makefile:
main: *.cpp *.h
g++ -o LSL lab1.cpp
clean:
rm -f *.o LSL*
私が得るエラー:
ここに私が得ているエラーがあります。Employee.cpp/Employee.h ファイルが表示されていないようです。何か案は??
unixserver:Lab1> make
g++ -o LSL lab1.cpp
/tmp/ccamnaqx.o: In function
createRecord()':
lab1.cpp:(.text+0x3fb): undefined reference to
Employee::Employee()'
lab1.cpp:(.text+0x477): undefined reference to Employee::setLastName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x4f2): undefined reference to
Employee::setFirstName(std::basic_string, std::allocator >)'
lab1.cpp:(.text+0x589): undefined reference to Employee::setId(int)'
lab1.cpp:(.text+0x5ce): undefined reference to
Employee::setSalary(int)'
lab1.cpp:(.text+0x60e): undefined reference to Employee::setDepartment(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x67c): undefined reference to
Employee::setPhoneNumber(std::basic_string, std::allocator >)'
lab1.cpp:(.text+0x6ea): undefined reference to Employee::setAddress(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x758): undefined reference to
Employee::setHireDate(std::basic_string, std::allocator >)'
lab1.cpp:(.text+0x7c6): undefined reference to `Employee::setEmailAddress(std::basic_string, std::allocator >)'
collect2: ld returned 1 exit status
make: * [main] Error 1
どんな助けでも大歓迎です!