Skip to content
← Back to Community
linker command failed, exit status one
Profile icon
elipie

The error:
main.cpp(stuff): undefined reference to 'mainLexer()'
How can I fix this?

I define the lexer struct to obj(i think its like that) and then I put:

lexer obj; obj.mainLexer();

I define it all, in the .h file... but it is still generating an error. Why is this and how can I fix it

Files:

//main.cpp #include <iostream> #include "error.h" #include "helpers.h" #include "Lexer.h" int main(){ lexer obj; obj.mainLexer(); //nothing yet }

Another file:

// Lexer.cpp #include <iostream> #include "setup.h" #include <string> #include <fstream> std::string tokens[ ] = {}; struct Token{ std::string type; std::string value; // This means i will turn it into a string example: 2 would turn into "2" // other int line; }; enum class Types{ Number, DoubleQuote, Quote, Initializer, LessThan, LargerThan, Equal, SlashOrComment, AtOrReturn, Pipe, LParen, RParen, LCurly, RCurly, RBracket, LBracket, Colon, SemiColon, Star, Plus, Caret, //more later. }; struct lexer{ int mainLexer(){ std::ifstream pie_file("tests.pie"); std::string tp; while(getline(pie_file, tp)){ std::cout << tp; // will later 'stringify' the line } return 0; } };

Anotha one:

#pragma once struct Token{}; enum class types{}; struct lexer{ int mainLexer(); }; int stringify(int intorsomething){ std::to_string(intorsomething); return 0; }

kthxbai

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
elipie
Comments
hotnewtop
Profile icon
Coder100

hai

Profile icon
Highwayman

W-what...
@Coder100

Profile icon
elipie

@Highwayman lmao, he got on the repl and helped me out there, so I marked it as the answer.

Profile icon
Highwayman

Ohh I was like what XD
@elipie

Profile icon
elipie