编译C多个文件时出错

时间:2017-11-18 17:54:58

标签: c++ class constructor cmake

我正在使用

  1. 的main.cpp
  2. FileSystem Class - 包含2个目录(root和current)
  3. 目录类 - 继承自BaseFile
  4. 文件类 - 继承自BaseFile
  5. 我尝试创建一个新目录并将其设置为root。 我的构造函数是:

    BaseFile::BaseFile() {
    name = "default";
    }
    Directory::Directory() {
        parent = nullptr;
        cout << "Directory: Default Constructor" << endl;
    }
    

    尝试使用FileSystem::FileSystem() { root = new Directory(); }

    我收到编译错误说:

        /Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/adammorad/ver1/cmake-build-debug --target ver1 -- -j 2
    Scanning dependencies of target ver1
    [ 33%] Building CXX object CMakeFiles/ver1.dir/FileSystem.cpp.o
    [ 66%] Linking CXX executable ver1
    Undefined symbols for architecture x86_64:
      "Directory::Directory()", referenced from:
          FileSystem::FileSystem() in FileSystem.cpp.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[3]: *** [ver1] Error 1
    make[2]: *** [CMakeFiles/ver1.dir/all] Error 2
    make[1]: *** [CMakeFiles/ver1.dir/rule] Error 2
    make: *** [ver1] Error 2
    

0 个答案:

没有答案