Code::Blocks

User forums => Using Code::Blocks => Topic started by: nazgai on August 03, 2012, 11:24:02 pm

Title: How to configure C::B debugging C++ project running flex and bison
Post by: nazgai on August 03, 2012, 11:24:02 pm
Hi everybody

I m looking for a while how to configure my C::B under Windows OS to :

 1) compile my file.l (flex file) w/ the "flex -i file.l" instruction
 -> output file should be lex.yy.c

 2) compile my file.y (bison file) w/ the "bison -d -v -W file.y" instruction
 -> output file should be parser.tab.h and parser.tab.c

 3) Compile all my C++ project, including my flex (lex.yy.c) and bison (parser.tab.h and parser.tab.c) C files (compiled just before) and my C++ libraries (lib/*.cpp)
 -> output file should be executable.exe

 4) Debugging my entire C++ compiled project

I almost try anything on C::B configuring "Project target option" or "Compiler and debugger"

I could not find any good tutorial on Google or into forums

Any help is welcomed
Title: Re: How to configure C::B debugging C++ project running flex and bison
Post by: ollydbg on August 04, 2012, 12:41:00 am
You can create a cb project, and put 1) and 2) to pre build steps, and put sources in 3) in the project source tree. (I'm not tried myself, so I may wrong :))
Title: Re: How to configure C::B debugging C++ project running flex and bison
Post by: nazgai on August 04, 2012, 01:08:42 am
Hey

Thanks for the advice, but seems that project tree is made to organize it but not compiling it w/ different compiler like flex & bison  :(
Title: Re: How to configure C::B debugging C++ project running flex and bison
Post by: oBFusCATed on August 04, 2012, 01:33:16 am
Have you read this: http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system ?
Title: Re: How to configure C::B debugging C++ project running flex and bison
Post by: nazgai on August 04, 2012, 11:21:29 am
Thank you very much oBFusCATed

I previously already read this wiki page but didn't success at the first try because :

I am using Flex and Bison, downloaded from GNU for windows.
 - That give me C file (lex.yy.c, parser.tab.c and parser.tab.h)

Compiling CPP code project
 - My project is a *.cpp file.

The problem was :
 - I create CPP C::B Project
 - Remove Main.cpp
 - Add lexer.l, parser.y and files.cpp to my C::B Project
 - Compile.

During the compilation happen 2 problems :
 1) Which file C::B has to compile first, second, etc... (normaly is 1.Flex, 2.Bison, 3.g++)
 2) Which compiler use ? (gcc, g++, flex, bison)

Answer 1 : C::B doesn't know which file has to be compiled first.
Answer 2 : C::B compile my parser.tab.c and my lex.yy.c w/ gcc instead of g++ (or didn't want to compile C file w/ g++) and my CPP file project w/ g++

To solve the problem

 1) Right click on both flex/bison files -> properties... -> Build -> check compile file and change the priority weight
 2) use flex and bison -o option to make ".cpp" output files and follow the wiki page http://wiki.codeblocks.org/index.php?title=Adding_support_for_non_C/C%2B%2B_files_to_the_build_system to create auto_generation files

Work well after all