I did try to find my specific issue, but the closest I found was this question where the issue was with global variables.
I need make a lexer header file along with it's cpp file to use in main.cpp. here are the two lexer files:
// lexer.hpp
#ifndef LEXER_HPP
#define LEXER_HPP
// Some include files, not really relevant
namespace interpreter
{
namespace lex
{
enum class TokType : char;
typedef std::vector<std::pair<TokType, std::string>> TokenList;
typedef std::pair<TokType, std::string> Token;
TokenList tokenizeString(std::string tokStr);
} // namespace lex
} // namespace interpreter
#endif
/* --------------------------------------*/
// lexer.cpp
// Again, some not-really-necessary include files
#include "lexer.hpp"
using namespace interpreter::lex;
enum class TokType : char {/* Stuff */};
TokenList tokenizeString(std::string tokStr) {/* Stuff*/};
When I use this stuff in main.cpp and compile, I get the following error:
/usr/bin/ld: /tmp/cc3XtuwW.o: in function `main':
main.cpp:(.text+0x7d): undefined reference to `interpreter::lex::tokenizeString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
Clearly, something is wrong with my function, but I cannot for the life of me figure out what is actually wrong.
Here's some other information if you need it:
- I turned my
lexer.cppinto a.ofile. Whether I use the.cppfile or the.ofile does not make a difference, though. - How I compiled
main.cpp:g++ -o main main.cpp lexer.o lexer.hpp,lexer.cpp,lexer.oandmain.cppare all in the same directory.
lexer.cppwhich I compile along withmain.cpp