Skip to content

Why the compiled object file is so huge? #1677

Description

@xchern

Just tried to use some very basic features with following source code:

#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main() {
    json j;
    std::cin >> j;
    std::cout << j["field1"];
}

The executable size is 3.05MB compiled with g++ (gcc version 9.1.0 (Rev3, Built by MSYS2 project)). Such a overhead is insane for a simple program. It is even bigger than the "json.hpp" header file (711KB).

I roughly viewed through the source code. Class methods are mostly defined in class body, which will be inlined automatically. And a lot of macros and templates are used. All these facts probably cause the bloat of binary size.

Is there any advice for reduce object file size?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions