Author Topic: How to configure C::B debugging C++ project running flex and bison  (Read 6374 times)

nazgai

  • Guest
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

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to configure C::B debugging C++ project running flex and bison
« Reply #1 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 :))
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

nazgai

  • Guest
Re: How to configure C::B debugging C++ project running flex and bison
« Reply #2 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  :(

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

nazgai

  • Guest
Re: How to configure C::B debugging C++ project running flex and bison
« Reply #4 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