Building Munt with optimizations

Developer's Forum for discussion of bugs, code, and other developmental aspects of the Munt Project.

Building Munt with optimizations

Postby x86++ » 2016-2-07 @ 02:21

-O2 Optimizations
The release build of the Munt library has a compiler flag for -O3 optimization, however, the -O2 produces a ~15% smaller static library (assume similar for shared library). Also, the C flag to link with these libraries doesn't seem necessary, and removing them had no effect on the compiled code of the static library: -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32.

Reducing size of library by --strip-unneeded
In addition to -O2 optimizations, "strip" reduces the size of the binary further. The -s option to remove all symbols and relocation information results in a non-working library (tested in dosbox). However, --strip-unneeded works for both library types and reduces size of binary by ~10%; this option keeps symbols needed by relocations.

Shared library requires C runtimes
Built shared library (dll file) with C/CPP interfaces along with the optimizations -O2 and --strip-unneeded which reduces the file size by ~50%. However, it is dependent on 2 external files (C/C++ runtime libraries in the case of mingw32/gcc462) and results in a runtime error upon exiting dosbox, although the music works as expected. This error is fixed by instead static linking these C runtimes with the shared Munt library; add: -static-libgcc -static-libstdc++ to the cmake option: CMAKE_SHARED_LINKER_FLAGS.

Attached this shared library (version d419d36) for verifying that it works in Windows.
You do not have the required permissions to view the files attached to this post.
Posts: 67
Joined: 2015-9-29 @ 07:40

Re: Building Munt with optimizations

Postby realnc » 2016-2-07 @ 13:02

If you want a smaller binary, build with -Os, not -O2.
User avatar
Posts: 450
Joined: 2010-10-13 @ 11:02

Return to MT-32 Development

Who is online

Users browsing this forum: No registered users and 1 guest