lundi 25 avril 2022

xcode : undefined symbols when including headers

I recently started a project using swift and c++. So I installed Xcode and started using it. I first encountered some bugs, but fixed theme.

However, I still got some Undefined symbols for architecture x86_64:

I searched online and I can't find the solution for my problem (otherwise I would not have asked the question).

This is the whole error :

  "parser(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, Node*, int, int)", referenced from:
      utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
  "recognize_paternes(Node*, bool)", referenced from:
      utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
  "ast_t_rep(Node*, int)", referenced from:
      utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
  "lex(char const*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&)", referenced from:
      utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
  "visitor(std::__1::vector<Node*, std::__1::allocator<Node*> >, bool, bool, bool)", referenced from:
      utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But I think we can just consider :

      utilise_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o

as this error seems to be redundant.

In my main.cpp file, I imported the header file (parser.h) where I declared Node *parser(vector<string>, Node *, int, int);.

In main.cpp>utilise_file(...), I call the function parser:

void utilise_file(){
    ...
    vector<string> code_ref = vector<string>();
    vector<string> lexeme = lex(source.c_str(), code_ref);
    Node *ast_t = new Node();
    ast_t->value = "main";
    ast_t->type = "root";
    Node *p = parser(lexeme, ast_t, 0, int(lexeme.size()));
   ...
}

So normally, I would not get this error.

It seems to me that it is a 'type' sort of problem, but I can't figure what.

I searched online for solutions, and I tried adding -Xlinker in Xcode>Linking>Other Liner Flags, but it didn't helped.

I also thought of adding the flags linking to the header in the compiling command line, but I think Xcode does that automatically. (Or not because many of my headers are not recognized in the file arborescence...)

Thank you for your help ;)

Aucun commentaire:

Enregistrer un commentaire