0

the following option

g++ main.cpp -E

will join all headers and renders macros. It does generate over 10MB output for me. I just need to render includes and not macros. And also I need to limit rendering includes to local files

#include "headerfile.hpp" 

I do not want to render

#include <iostream>

I dont want such horrible code:

namespace std __attribute__ ((__visibility__ ("default")))
{

# 60 "/usr/include/c++/4.8/iostream" 3
  extern istream cin;
  extern ostream cout;
  extern ostream cerr;
  extern ostream clog;


  extern wistream wcin;
  extern wostream wcout;
  extern wostream wcerr;
  extern wostream wclog;

Is there any way to limit option E to what I need?

barej
  • 1,330
  • 3
  • 25
  • 56
  • Preprococess or do not preprocess - there is no half-way house. – Paul R Feb 08 '15 at 09:04
  • @PaulR I just want to merge a library. is there any better solution? – barej Feb 08 '15 at 09:07
  • What do you mean by "merge a library" ? – Paul R Feb 08 '15 at 09:07
  • i want my `main.cpp`, `header1.cpp`, `folder1/header2.cpp`, ... `folder10/header78.cpp` which are all included in `main.cpp` (or included from each other) to be merged into one file called `joined.cpp` . So when I compile the single file `joined.cpp` I get the same results. – barej Feb 08 '15 at 09:14
  • OK - just use `cat` then. – Paul R Feb 08 '15 at 09:16
  • @PaulR cat does not consider which file includes which and it does not consider the order of files. maybe `header1.hpp` calls `header63.hpp` so `header63.hpp` must be placed before `header1.hpp`. cat cannot handle it. – barej Feb 08 '15 at 09:23
  • OK I would suggest `m4` then - it understands #includes and won't expand macros - you would still need to filter out system #includes though, perhaps using something like 'sed` to filter the source first. – Paul R Feb 08 '15 at 10:15
  • @PaulR `g++: error: unrecognized command line option ‘-m4’` how should I use it? – barej Feb 08 '15 at 10:41
  • No, `m4` is a preprocessor, not a command line option. It should be in /usr/bin on pretty much any *nix installation. – Paul R Feb 08 '15 at 10:52

0 Answers0