I have to use a header file after the program is compiled. This header is downloaded from a server due to a client petition. Inside the header there are 3 arrays and 1 int that I would like to read during execution.
My first solution is to write a parser. The header files always have the same pattern so I could write 4 lines to read the arrays and the int.
Is there any other solution? Perhaps a dynamic include and a precompiled header, ho knows.
This is the full explanation:
I’m developing a native Android application using Qualcomm AR SDK.
One technique to use your own 3D models is using this perl script: http://heikobehrens.net/2009/08/27/obj2opengl/. Basically you need 2 files: a header with vertices, normals and texture coordinates, and the texture. The above script can generetate this header from a .obj file.
Ok, now you have both files ready to use in native C/C++ to render the model. You can COMPILE this header and include it anywhere you want in your application. But my application needs to download this header and texture when the user presses a button, for example. The texture it’s easy to read, but I also need to read the header at EXECUTION time. Because I am not a C/C++ expert I asked here if there was a chance to link the header at execution time.
But now it don’t matter beacuse I’ve writed a parser so I can use the vertices, texture coords and normals at execution time.
C++ is (usually) a statically compiled language. You compile it, and get some executable code out, which you can run. The two stages, before and after compilation, have nothing to do with each others. At compile-time, you deal with C++ source code only.
And at runtime, you deal with a single compiled program, generated from all the source code.
There is generally no way to “add” source code to a program once it has been compiled.
(I’m simplifying a bit here, I hope the nitpickers will forgive me)
What you need to do instead is treat that “header” as data, not code.
It is a data file containing three arrays and an int. You need to write your program to open that file, read its contents, parse it, and carry out the actions necessary.
To do that, you’ll need to look into file I/O to load the file, string manipulation to process its contents, and then some logic to create the variables to hold the data specified in the data file.
But you can’t just “plug in” new code.