0

I have two C/C++ executable projects in a solution. The output for one of the projects is needed for the other; think of the second project like an installer of some sort (it's not, so I don't need an installer project, but it'll read the output of the second project as though it were).

Is there some way I can convert the raw data from the first project's output into something usable from compile time? Something like this is what I had in mind:

// build order is set so this second project is built after the first is completed

/*c++ constexpr*/ unsigned char ProjectOneOutput[ ] =
    SOME_PREPROCESSOR_MACRO_TO_READ_FILES( PROJECT_ONE_OUTPUT_PATH );

// code that uses ProjectOneOutput goes here

Edit: These answers will not work.

  1. External linkage isn't what I'm looking for, unless there is a way to do it directly in the file.

  2. This is not raw C/C++, it requires an external program.

  3. The file is a PE, thus it cannot be enclosed in STR( ).

Cryptography Man
  • 189
  • 2
  • 10

2 Answers2

1

There is no preprocessor facility which would let you read a binary file. But there's nothing stopping you from writing a little program or even shell script which reads a binary file and outputs C code which would initialise a char array to the contents of the file.

Your program could then #include the generated file. So all you need to do is to add your conversion program into the build procedure.

rici
  • 234,347
  • 28
  • 237
  • 341
  • I don't want to have an external program, that defeats the whole purpose of the project relying on itself. – Cryptography Man Oct 14 '18 at 23:13
  • @cryotography: it's not an external program, it's part of the build system (and contained in the project). You don't need to distribute it with the compiled code any more than you need to distribute the C++ compiler you are using. It's not even a DLL. Once the compile is complete, it's job is done. – rici Oct 15 '18 at 00:59
  • So you mean add a project that reads and creates a file with the unsigned char array with the data? How would I get this project to run before the dependent project compiles? – Cryptography Man Oct 15 '18 at 03:20
  • @cryptographyman: sadly, I know nothing of how to configure build recipes with Visual Studio. With a standard bsd-like makefile, it's trivial and solutions like this are quite common. I'm sure it's equally trivial in Visual Studio, since complex projects with code generators are also compiled in that environment. – rici Oct 15 '18 at 03:29
0

Resources are the way to go. I can update this answer to have more detail if anyone wants.

Cryptography Man
  • 189
  • 2
  • 10