0

I have code that compiles correctly in Visual Studios. I need to compile it using g++ but when I do I get a something like the text below. From what I understand this means it's not properly linking he header file that the undefined references are supposed to come from. The way I am linking them is also posted. Please suggest a fix?

extern "C" 
{
    #include "lexer.h"
}

"COMPILE_FAIL Source.cpp: In function ‘void checkForAllRightEpsilon()’: /tmp/ccQGWPkN.o: In function parseFile()': Source.cpp:(.text+0xe86): undefined reference togetToken' ... /tmp/ccQGWPkN.o:Source.cpp:(.text+0x1249): more undefined references to `token' follow"

robo
  • 7
  • 5
  • Was `lexer.c` compiled using `gcc` (i.e. the c-compiler), not `g++` actually? – πάντα ῥεῖ Feb 18 '15 at 18:58
  • No, it was compiled using g++. – robo Feb 18 '15 at 19:11
  • _"No, it was compiled using `g++`"_ Then this was probably wrong, use `gcc` to compile it as c-code. The marked duplicate has some explanations about c++ name mangling, and how linkage is affected by this. – πάντα ῥεῖ Feb 18 '15 at 19:15
  • The compiler automatically compiles as g++. The three files are main.cpp, lexer.c, and lexer.h. I believe it is compiling correctly in this respect? – robo Feb 18 '15 at 20:13
  • _"The compiler automatically compiles as g++."_ What do you mean? How is it called? From an IDE or a makefile? You either remove the `extern "C"` block surrounding the `#include "lexer.h"` statement, or manage getting `lexer.c` compiled as plain c code. – πάντα ῥεῖ Feb 18 '15 at 20:14

0 Answers0