[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: nlohmann-json3-dev need to be reverted to trixie version



Hello Gianfranco,

* Gianfranco Costamagna <locutusofborg@debian.org> [2025-09-17 09:26]:
Question, isn't this covered by

#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
    #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
        #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0
            #warning "Already included a different version of the library!"
        #endif
    #endif
#endif

#define NLOHMANN_JSON_VERSION_MAJOR 3   // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_MINOR 12  // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_PATCH 0   // NOLINT(modernize-macro-to-enum)

code?
I was thinking about the following scenario:

libfoo uses nlohmann-json internally, does not expose it via public headers but also does not hide the symbols with -fvisibility=hidden, so they end up being exported from libfoo.so (alternatively: libfoo is a static library, which has no concept of hidden symbols)

Now, if you write a program that uses a different version of nlohmann-json and also links against libfoo, you end up with duplicate symbol definitions. In theory, the linker is allowed pick *any* version of a symbol because of the One Definition Rule, potentially breaking stuff quite horribly. And the above warning will never trigger because you never included nlohmann-json headers twice in the same compilation unit.

In practise, you will almost certainly have all the required definitions available for each compilation unit (because nlohmann-json is header only), so it is unlikely that the compiler emits symbol references which might later at the linker stage be resolved with the wrong version. Therefore, you will almost always get away with it.


Cheers
Timo

--
⢀⣴⠾⠻⢶⣦⠀   ╭────────────────────────────────────────────────────╮
⣾⠁⢠⠒⠀⣿⡁   │ Timo Röhling                                       │
⢿⡄⠘⠷⠚⠋⠀   │ 9B03 EBB9 8300 DF97 C2B1  23BF CC8C 6BDD 1403 F4CA │
⠈⠳⣄⠀⠀⠀⠀   ╰────────────────────────────────────────────────────╯

Attachment: signature.asc
Description: PGP signature


Reply to: