2016-11-25 22 views
0

Deitel的Book C++ 9e中的fig03_13.cpp文件不能編譯。「將接口與實現分離」C++ Deitel 9e Book(如何編譯?)

$ g++ fig03_13.cpp 
/tmp/cckud0qb.o: In function `main': 
fig03_13.cpp:(.text+0x4b): undefined reference to `GradeBook::GradeBook(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' 
fig03_13.cpp:(.text+0xa0): undefined reference to `GradeBook::GradeBook(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' 
fig03_13.cpp:(.text+0xce): undefined reference to `GradeBook::getCourseName[abi:cxx11]() const' 
fig03_13.cpp:(.text+0xe4): undefined reference to `GradeBook::getCourseName[abi:cxx11]() const' 
collect2: error: ld returned 1 exit status 

$ g++ -v 
Using built-in specs. 
COLLECT_GCC=g++ 
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/6.2.1/lto-wrapper 
Target: x86_64-redhat-linux 
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux 
Thread model: posix 
gcc version 6.2.1 20160916 (Red Hat 6.2.1-2) (GCC) 

https://gitlab.com/moisesroj0/deitel/tree/master/C++%209e/Code_Examples/ch03/fig03_11_13

+0

的問題也被稱爲「鏈接文件以g ++ http://stackoverflow.com/questions/6532400/linking-files-在-克 –

回答

0

至少需要:

g++ GradeBook.cpp fig03_13.cpp