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( ).

2
  • 1
    Modify the first program to output a header file? Commented Oct 14, 2018 at 2:15
  • What do you mean? The first file is a PE. It can't just be made into a "header file". Also, I don't see the purpose into making it a header file. Commented Oct 14, 2018 at 2:26

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I don't want to have an external program, that defeats the whole purpose of the project relying on itself.
@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.
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?
@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.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.