3

Hi1 I just created a DLL with GCC. It only contains this simple function:

extern "C" {
    char* Message() {
        return (char*)"Cool";
    }
}

The resulted file's size is 42 Kb and I don't understand why is it so big, when a simple executable that creates and shows a GUI window only weights 8 Kb. Is there a way of reducing the size of the shared library? Why is it so big? Thanks!

UPDATE

If I create the same file with Code::Blocks, it only has 24 Kb. I wonder what way does CB create it in order to achieve that size?

UPDATE

It matters because I want to know that my library doesn't contain unnecessary code. My GCC command to create the DLL is:

gcc -c Source/MyLib.cpp -s -Os -nostartfiles -nostdlib -nodefaultlibs -o MyLib.o
ar  rcs libMylib.a MyLib.o
gcc -shared -o MyLib.dll MyLib.o
4
  • Why does it matter to you? And what options to gcc have you given (gcc -Wall -O3 ?) May 25, 2012 at 16:10
  • Why don't you compile with gcc -fPIC -shared -Os Source/MyLib.cpp -o MyLib.dll ? May 25, 2012 at 16:49
  • Yes, thanks. Yet, the same size.
    – ali
    May 25, 2012 at 16:55
  • Moreover, the -fPIC is ignored on my x86
    – ali
    May 25, 2012 at 16:56

1 Answer 1

2

Add -s to the linking state (gcc -s -shared -o MyLib.dll MyLib.o)

1
  • You are the boss. From 42Kb to 8Kb. Thanks to everyone!
    – ali
    May 25, 2012 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.