User forums > Using Code::Blocks

DLL Exported function list - is too exhaustive - things I don't want in there!

<< < (3/3)

MortenMacFly:

--- Quote from: adder6 on March 22, 2011, 08:48:07 pm ---I have now solved this problem, at least it appears that way for now. If anyone is interested or you think it might be useful please say so on this topic and I will post steps showing exactly how I did it. Many thanks :D

--- End quote ---
...sure.

adder6:
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:


--- Code: ---// 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;
}
--- End code ---

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:


--- Code: ---;test.def
;The following functions are exported from this DLL
LIBRARY   "test.dll"
EXPORTS
   Double   @1
--- End code ---

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):


--- Code: ---g++ -shared -Wl,--output-def=newtest.def -o newtest.dll test.def example.o
--- End code ---

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:


--- Code: ---LIBRARY "test.dll" BASE=0x67780000
EXPORTS
    Double @1
--- End code ---

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:


--- Code: ---EXPORTS
    Double @1
    _Z6Treblei @2
--- End code ---

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:

adder6:
I'm a bit embarassed here but I think this might all simply be possible by just typing the full filename of your def file in the linker options in the project build options.

By right clicking on the project and going into project build options and going to the linker settings tab, you can then go to the 'Other linker options' field and just type in your .def file's name and then compile and build. So far this seems to have exactly the same effect as all those lengthy steps I posted above :?

Navigation

[0] Message Index

[*] Previous page

Go to full version