Adding an object file to a C project in Visual Studio

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im looking for the best way to add an existing object file to a project from within the VS IDE. The existing object file is a blob created with ld from a file called data.txt. The txt file contains a huge string, its not C source code.<br/>

[create object file: ld -r -b binary -o data.o data.txt]
cl -c main.c
link data.o main.obj /OUT:test.exe
The executable works as expected on the command line, it can address the data in the data object file. No problem there.<br/>

Q: How can I build the same in a project in the VS2010 or VS2012 IDE?
If it helps, heres a code example for main.c.
<pre class="prettyprint" style=" #include <stdlib.h>
#include <stdio.h>

extern char binary_data_txt_start[];
extern char binary_data_txt_end[];
extern unsigned long binary_data_txt_size;

int main (int argc, char *argv[])
{ unsigned long a=0;
char *p;
p=binary_data_txt_start;

printf("start: %ldn", &binary_data_txt_start);
printf(" end: %ldn", &binary_data_txt_end);
printf(" size: %ldn", &binary_data_txt_size);

printf("%xn", p[0]);
p[10]=;
printf("%sn", p);

return 0;
}[/code]
This will show start and end numbers, size, show the first character as hex, and it will print the first 10 characters of the large string.<br/>

The code must be portable to Linux/Unix, thats why Im not using resource files.
The text is larger than 64 kB, too large for a single char * variable.

<br/>
<br/>

View the full article
 
Back
Top