Home > Enterprise >  Build errors using Firebase SDK (VS2019/C 11) in a Windows desktop app (VS2022/C 14)
Build errors using Firebase SDK (VS2019/C 11) in a Windows desktop app (VS2022/C 14)

Time:10-13

I'm trying to add Google Firebase/Firestore to an existing Windows C desktop app using VS 2022. I've downloaded and installed the latest version of the Firebase C SDK.

I added some very simple Firebase code to my app, just to test that the system built okay. The code compiled fine, I got many link errors which I haven't been able to resolve. They all seem to be related to usage of the Standard Library.

Here is the code:

#include "firebase/firestore.h"

void TestFirestore()
{
    firebase::App *app = firebase::App::Create();
    firebase::firestore::Firestore *db = 
    firebase::firestore::Firestore::GetInstance();
}

This compiled with no problems, but generated about 100 link errors - both missing and duplicated symbols, such as:

msvcprtd.lib (MSVCP140D.dll) : error LNK2005:
"public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ)
already defined in firebase_firestore.lib
(7ba01613985f32fe50e0c125a0414f54_firebase_firestore.dir_Debug_document_reference.obj)

firebase_app.lib (d3d7d08a438878e74aeb2cbaaedfc967_flatbuffers.dir_Debug_util.obj) :
error LNK2001: unresolved external symbol
"private: static int std::locale::id::_Id_cnt" (?_Id_cnt@id@locale@std@@0HA)

I'm statically linking to the pre-built x86 libraries provided with the Firebase C SDK, which was built using VS 2019 and C 11. I'm using VS 2022 using C 14. (I'd be happy to use C 11, but VS no longer supports C 11).

In any case, according to this answer Is it safe to link C 17, C 14, and C 11 objects, C 11 and C 14 should have ABI compatibility and there should not be a problem linking the two, providing they used the same compiler.

So that leaves the question of whether there is a problem using VS 2022 when the Firebase SDK was built using VS 2109. According to everything I've read, this should be okay, but then I've no idea what's causing the abover errors. I could downgrade to 2019 just to make sure, but it was a non-trivial task setting up my current build environment and Microsoft makes it difficult to install anything but the latest version of VS.

Any help or advice would be greatly appreciated.

CodePudding user response:

Turns out the problem was a bug in the MSVC compiler! As described in this issue, the VS dev team broke the binary backwards compatibility promised in in this article.

The problem was solved by upgrading to the latest version of the compiler - 17.3.x or later.

  • Related