i want to convert function to an object file..is it possible?

V

veereshai

i want to copy the functions from my source file into a new file...and
convert each function into a new object file by compiling it. now, i
want to invoke the function using the object file i have created and
not by invoking the original function(i.e delete the part which has the
function and then try to invoke the same function by including the
object file into my source code). Is this possible?
 
M

Mabden

i want to copy the functions from my source file into a new file...and
convert each function into a new object file by compiling it. now, i
want to invoke the function using the object file i have created and
not by invoking the original function(i.e delete the part which has the
function and then try to invoke the same function by including the
object file into my source code). Is this possible?

Why are you trying to do this? What are you trying to accomplish? There
may be some other way you haven't thought of. Tell us the problem you
trying to solve, not your weird solution. Or at least try your solution
first and tell us what you expected and what went wrong.

I don't see how you can include and object file in your source code, as
it is probably a binary file. It doesn't make sense. You could possibly
convert the C code to Assembler and put the assembly source within an
ASM {} block or whatever (I forget the exact syntax for embedding
assembler in C).

I think object files may have offsets or stack manipulations that would
be incorrect when you compiled the new source, so even the assembler
code may not work. I may be wrong, as it could be the linker that does
this.

Classification: Bad Idea.
 
J

Jack Klein

Why are you trying to do this? What are you trying to accomplish? There
may be some other way you haven't thought of. Tell us the problem you
trying to solve, not your weird solution. Or at least try your solution
first and tell us what you expected and what went wrong.

I don't see how you can include and object file in your source code, as
it is probably a binary file. It doesn't make sense. You could possibly
convert the C code to Assembler and put the assembly source within an
ASM {} block or whatever (I forget the exact syntax for embedding
assembler in C).

You didn't forget, there is no syntax for putting assembly language
source code in a C source file, other than perhaps inside a comment
block.
 
W

Walter Roberson

:i want to copy the functions from my source file into a new file...and
:convert each function into a new object file by compiling it. now, i
:want to invoke the function using the object file i have created and
:not by invoking the original function(i.e delete the part which has the
:function and then try to invoke the same function by including the
:eek:bject file into my source code). Is this possible?

If what you mean is that you want to break your source file into
seperate files, one function per file, and then combine the new set
of files into an executable (rather than having a monolithic
source file), then Yes, you can often do that.

C promises that *some* mechanism will exist for linking
files together. C does not, however, put any constraints
on what the commands (or graphics environment) will look
like for telling the compiler that you want to do this.

If your compiler uses a command line, then often you can
accomplish what you {perhaps} want by listing all of the source
file names instead of just the one file name. For example,
if your command line happens to look like

Compile hello.c Producing hello.exe

then possibly a command line such as one of these would work:

Compile init.c whoami.c printout.c Producing hello.exe
or
Compile init.c And whoami.c And printout.c Producing hello.exe
or
Compile {init.c,whoami.c,printout.c} Producing hello.exe

But on the other hand you might have to use something like

Compile init.c Halfway Producing init.obj
Compile whoami.c Halfway Producing whoami.obj
Compile printout.c Halfway Producing printout.obj
Compile More init.obj Producing hello.exe
Compile More whoami.obj Merging Into hello.exe
Compile More printout.obj Merging Into hello.exe


The precise compile mechanism depends upon your operating system
and the compiler you are using, and you would need to ask in
a newsgroup that deals with that compiler on that operating system.
Or better yet, first read the documentation about your compiler.


And before you try the above: I made the syntax up for this posting.
I'd be -quite- surprised if it happens to match any real system.
So RTFM (Read The Fine Manual.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top