ali
ali

Reputation: 11045

Reduce size of DLL created directly with GCC

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

Upvotes: 3

Views: 574

Answers (1)

lazy_banana
lazy_banana

Reputation: 460

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

Upvotes: 2

Related Questions