vendredi 31 décembre 2021

Undefined symbols for architecture x86_64 while make install using Cmake

I'm trying to build a project which contains main.cxx Control.cxx Control.hxx Event.cxx and Event.hxx, but it says:

Undefined Symbols for architecture x86_64
"Control::LoadDataFile()", referenced from:
      _main in main.cxx.o
  "Control::Control(char const*)", referenced from:
      _main in main.cxx.o
  "Control::~Control()", referenced from:
      _main in main.cxx.o

when I try to make install. Here are my codes: main.cxx inside timeline/app

#include<iostream>

#include"Control.hxx"
#include"Event.hxx"

int main(){

  Control usage;
  usage.LoadDataFile();

  return 0;
}

Control.cxx inside timeline/src

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>

#include"Control.hxx"
#include"Event.hxx"




Control::Control(char const* InputDataFile)
    :DataFile(InputDataFile)
  {
    std::cout<<"Welcome to timeline searching system"<<endl;
}
Control::~Control(){
}

void Control::LoadDataFile(){
    std::cout<<"Loading data file..."<<endl;
    ifstream input_file(DataFile);

    while(getline(input_file,line)){
      line>>Year>>Month>>Day>>Name>>Content;

      Event* event = new Event(Year, Month, Day, Name, Content);
      Events.push_back(event);
    }
    std::cout<<"Loaded all data"<<endl;
}


void Control::CreateEvent(){

  }

void Control::DeleteEvent(){

  }

void Control::DisplayEvents(){
    if(!Events) std::cout<<"Can not find events!"<<endl;
    for(std::vector<Evnet*>::iterator ev_iter = Events.begin();
          ev_iter != Events.end(); ++ev_iter){
      std::cout<<ev_iter->Get("Year")<<"."<<ev_iter->Get("Month")<<"."<<ev_iter->Get("Day")<<": with"<<ev_iter->Get("Name")<<endl;
      std::cout<<ev_iter->Get("Content")<<endl;
    }

    std::cout<<"All events have been displayed."<<endl;
  }

void Control::SearchEvent(){

  }

Control.hxx inside timeline/src

#include<vector>

#include"Event.hxx"

class Control {
public:
  Control(char const* = "../input/timeline.txt");
  ~Control();

  void LoadDataFile();

  void CreateEvent();
  void DeleteEvent();
  void DisplayEvents();
  void SearchEvent();

private:
  char* DataFile;
  std::vector<Event*> Events;

};

Event.cxx inside timeline/src

#include"Event.hxx"


Event::Event(int const InputYear, int const InputMonth, int const InputDay, char const* InputName, char const* InputContent)
       :Year(InputYear), Month(InputMonth), Day(InputDay), Content(InputContent), Name(InputName)
  {

  }

Event::~Event(){
}

Event.hxx inside timeline/src

ifndef Event_hxx_
#define Event_hxx_

template <typename Type>
Type const& Get(Type const& value)
{
  return value;
}

class Event {
public:
  Event(int const* InputYear, int const* InputMonth, int const* InputDay, char const* InputName, char const* InputContent);
  ~Event();

private:
  int Year;
  int Month;
  int Day;
  std::string Content;
  std::string Name;

  template <typename Type> friend Type const& Get(Type const& value);

};

#endif

And finally the CMakeLists.txt at source directory

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(TimeLine_Searching_System)

#add source directory
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

add_executable(TimeLine_Searching_System app/main.cxx)

#target_link_libraries(TimeLine_Searching_System PUBLIC src)

target_include_directories(TimeLine_Searching_System PUBLIC
                          "${PROJECT_BINARY_DIR}"
                          "${PROJECT_SOURCE_DIR}/src"
                          )

install(TARGETS TimeLine_Searching_System DESTINATION bin)

Could some one tell me what I did wrong? I'm really a noob.

Aucun commentaire:

Enregistrer un commentaire