Dynamic includes/linking

A

Ajinkya

I have writen a program for a game called game.exe
Now it includes a player part to which has to be a function to be
writen by someone else.

Now I want to provide this exe to some tester who will be writing his
player function.

I dont know his file name and his function name....he will have to
include it.
I am providing him the game.exe and a common file containing all the
includes(which is in turn included in my code)
He will have to include his file through this common includes file.

But as includes are compile time even after changes in the common
includes file doesnot change the exe behaviour.

I want to dynamically include his file/code at runtime/dynamic through
the common includes file...

How can i go about regarding this problem ?

Thanks,
Ajinkya
 
B

Ben Bacarisse

Ajinkya said:
I have writen a program for a game called game.exe
Now it includes a player part to which has to be a function to be
writen by someone else.

Now I want to provide this exe to some tester who will be writing his
player function.

I dont know his file name and his function name....he will have to
include it.
I am providing him the game.exe and a common file containing all the
includes(which is in turn included in my code)
He will have to include his file through this common includes file.

But as includes are compile time even after changes in the common
includes file doesnot change the exe behaviour.

I want to dynamically include his file/code at runtime/dynamic through
the common includes file...

How can i go about regarding this problem ?

The facilities provided by standard C (the topic in this group) in the
respect are rather limited (you can try to run a program, but not much
more). You'll get more helpful answers in a group that discusses the
facilities of your system. The .exe suggests you want a Windows
programming group.
 
A

Ajinkya

The facilities provided by standard C (the topic in this group) in the
respect are rather limited (you can try to run a program, but not much
more). You'll get more helpful answers in a group that discusses the
facilities of your system. The .exe suggests you want a Windows
programming group.
Exactly...cause in unix there is a method i have found but it is
platform dependent way.
I want this to work in windows....is this anything related to dll ? I
know rather nothing of dll but heard of it...just a guess...
 
B

Ben Bacarisse

Ajinkya said:
Exactly...cause in unix there is a method i have found but it is
platform dependent way.
I want this to work in windows....is this anything related to dll ? I
know rather nothing of dll but heard of it...just a guess...

No, there is nothing in standard C about DLLs.

If you need a portable solution, maybe you can do it by linking (or
even compiling) the "guest" code?

If you need some more info about DLLs, post in a Windows programming group.

PS. Don't quote sigs (the bit after the "-- ").
PPS. Try to trim the message you reply to.
 
G

Gordon Burditt

I have writen a program for a game called game.exe
Now it includes a player part to which has to be a function to be
writen by someone else.

Now I want to provide this exe to some tester who will be writing his
player function.

I dont know his file name and his function name....he will have to
include it.

You might be able to use dynamic linking to link to a "plugin".
However, this is not a part of standard C and will require
system-specific features, if they are available. You may be able
to accept the file name of the plugin as, say, a command-line
argument.

There is no "dynamic include".
I am providing him the game.exe and a common file containing all the
includes(which is in turn included in my code)
He will have to include his file through this common includes file.
But as includes are compile time even after changes in the common
includes file doesnot change the exe behaviour.

Even for a plugin, changes in common includes require re-compilation
of all the pieces that use them. It is best to find an interface for
the plugin and not change it much.
I want to dynamically include his file/code at runtime/dynamic through
the common includes file...

Plugins are usually done by separate compilation, not by including
a whole bunch of files in one big compilation. Changing the code
in the plugin requires recompilation of the plugin only.
 
A

Ajinkya

Can you give me an example how this can be done ?
I didnt get exactly what do you mean by a plugin..
Can you give a small example of the design you are suggesting ?
 
G

Gordon Burditt

Can you give me an example how this can be done ?

There's no standard way to do this; it's all system-specific.
I didnt get exactly what do you mean by a plugin..

In some implementations, you can call a function dlopen(), which
takes a file path name as an argument, to load a shared object
(plugin). This object is compiled and linked separately from the
main executable. You may then call dlsym() or dlfunc() with the
name of a symbol to get a function pointer to the function named,
and use that pointer call the function.

This is different from a "normal" shared library use, where no
special calls are required by the program to use the library because
it's all set up before the program starts running using the libraries
specified to the linker.
Can you give a small example of the design you are suggesting ?

Apache (the web server program) as implemented on FreeBSD (and
presumably other BSD Unix variants and Linux) uses a number of
plugins which can be specified in a configuration file at runtime.

Although a lot of the details may be different, Windows *.dll files
can be used in a similar way.
 
M

Mark McIntyre

Can you give me an example how this can be done ?

There's no standard way - you would need to ask the specialists in a
group which is dedicated to your operating system and/or compiler.
I didnt get exactly what do you mean by a plugin..
Can you give a small example of the design you are suggesting ?

http://en.wikipedia.org/wiki/Plugin

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top