0
votes

I'd like to use the yacc/bison parser for my own project. When building the Parser with my own Makefile, everything works fine. I took the sources from http://ymorin.is-a-geek.org/projects/kconfig-frontends (just the parser that's: /<path-to-kconfig>/libs/parser.

Now when including these files into the C++ project in Eclipse, after hitting make, the compiler crashes at the .y file, because of a syntax error - wasn't able to read the .y - syntax. So I excluded the parser from the building process.

In the answer of Yacc and Lex inclusion confusion, I've read that only the .h files have to be included, to use the functions of the parser.

So what I did is:

  • To get access to the parser sources out of my project, I created a simple function that just prints a line on the console in yconf.y and yconf.c: void testout(char *txt) {printf(txt);}
  • I even created a yconf.h with the function-head void testout(char *txt);
  • compiled the parser with my own makefile
  • the main, where I'd like to call the function looks like:

    #include "y.tab.h"
    #include "yconf.h"
    #include <stdio.h>
    
    extern "C"{
    int main(int argc, char *argv[])
    {
        char configIn[] = "test";
        printf(configIn);
    
        testout(configIn);
    
        return 0;
    }
    }
    

The error

And now when compiling, an error appears: undefined reference to 'testout(char*)'. But Eclipse itself can resolve the function - when clicking that function, the yconf.h opens. And that's why I don't know where exactly the problem is.

Eclipse Settings:

In /project/properties/C/C++ Build/Settings I put the same include paths to the parser-sources for gcc and g++ and the linker. Additionally I added in this settings as "Include files" the y.tab.h and the yconf.h

If more information are needed, please ask.

I appreciate any advises about how to solve this problem. Thanks for the support

Kind Regards

1

1 Answers

2
votes

Okay one really just need the y.tab.h and y.tab.c. That is created with this makefile:

lex ./lconf.l
bison -d -y ./yconf.y

My error was: I was programming in C++ and I had the extern "C" command at the wrong place, that header file needs to be declared as c format. Here's the right code:

extern "C"{
    #include "y.tab.h"
}

int main(int argc, char *argv[])
{

    char configIn[] = "test";  
    testout(configIn);
    return 0;
}

(testout is a function in y.tab.h/c with a simple printf of the parameter configIn - when executing "test" was printed.)

BTW: I excluded all source files of the parser for compilation but of the y.tab.c