“将接口与实现分离”C ++ Deitel 9e Book(如何编译?)

时间:2016-11-25 01:44:06

标签: c++ compiler-errors

来自Deitel的Book C ++ 9e的fig03_13.cpp文件无法编译。

$ 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

1 个答案:

答案 0 :(得分:0)

至少你需要:

g++ GradeBook.cpp fig03_13.cpp