Ok I'll be honest this is rough as hell at the moment although perfectly functional. But to anyone who knows a bit about this or who doesn't know anything about it but has spent several days searching trying all kinds of solutions to the problem - this should be child's play.
1)I wrote a simple .cpp file containing two functions. One name Double and one named Treble. Both take a plain good old int as an argument and return it either doubled or trebled depending on which function you call. The file has no header attached:
// file example.cpp
#include <stdio.h> // this include may be unnecessary - probably forgot to remove it
extern "C"
{
int Double(int x)
{
return 2 * x;
}
}
int Treble(int x)
{
return 3 * x;
}
2)I compiled and built the .cpp file to make a typical object .o file from example.cpp.
3)I made a standard .DEF file contents as follows:
;test.def
;The following functions are exported from this DLL
LIBRARY "test.dll"
EXPORTS
Double @1
File's name is test.def.
4)I navigated to the installation folder of CB and then navigated to the 'MinGW' folder and then finally the 'bin' folder. This seems to stop those nasty No Such Directory Errors - for some reason doing stuff here allows g++ to get access to a load of stuff it needs to run - don't ask me why. I place both the 'test.def' file and the 'example.o' file in this 'bin' folder.
5)Opening the command line I navigated to the same place (the 'bin' folder in the CB 'MinGW' folder).
6)I then inputted the following command (I'm fairly sure this is correct may need to check it):
g++ -shared -Wl,--output-def=newtest.def -o newtest.dll test.def example.o
The program runs, reads the original .def file ('test.def') and outputs a new .def file ('newtest'.def) and a new dll ('newtest.dll') which has only the exports stated in the original 'test.def' file exported. I check it when I opened up newtest.def it had this:
LIBRARY "test.dll" BASE=0x67780000
EXPORTS
Double @1
Great! When I ran a program that linked against this it was fine, and if I tried to access function 'Treble' it borked as it should because it wasn't requested to be exported. Normally when just building through CB the output .def file looked like this:
EXPORTS
Double @1
_Z6Treblei @2
With that damn unwanted name mangled Treble function. So I guess maybe that's it. Obviously now you/I would/will have to build on this to get dependency files into the commands and stuff but that's a fairly lengthy but obvious process which can be done by just checking the full command line output from CB and working out how it's done.
I hope that's useful
**Note in the .def files I state the name of the library is 'test.dll' but I asked the program to output 'newtest.dll' as the output. This might screw something up when linking against it but again should be easy to fix probably just need to change the command line instruction to output 'test.dll' not 'newtest.dll'. It's only rough at the moment anyway but I'm sure you get the idea :wink: