firebase-cpp-sdk
firebase-cpp-sdk copied to clipboard
[Bug] Linker error using firestore from prebuilt binaries on Desktop/Windows
[REQUIRED] Please fill in the following fields:
- Pre-built SDK from the website or open-source from this repo: Yes, affects 9.1.0, 9.2.0
- Firebase C++ SDK version: 9.1.0 and 9.2.0
- Problematic Firebase Component: Firestore
- Other Firebase Components in use: App, Auth
- Platform you are using the C++ SDK on: Windows
- Platform you are targeting: Desktop/Windows
[REQUIRED] Please describe the issue here:
When building a Visual Studio 2019 application using the prebuilt SDK 9.1.0 or 9.2.0 that uses firebase::firestore::Firestore::GetInstance(app, &result);
, a linker error LNK2001 is preventing from successful compilation:
1>firebase_firestore.lib(c40555a92d77c30bdfba309b7446a52d_re2.dir_Debug_re2.obj) : error LNK2019: unresolved external symbol __std_init_once_link_alternate_names_and_abort referenced in function "public: __cdecl std::_Init_once_completer::~_Init_once_completer(void)" (??1_Init_once_completer@std@@QEAA@XZ)
1>firebase_firestore.lib(c40555a92d77c30bdfba309b7446a52d_re2.dir_Debug_dfa.obj) : error LNK2001: unresolved external symbol __std_init_once_link_alternate_names_and_abort
1>firebase_firestore.lib(c40555a92d77c30bdfba309b7446a52d_re2.dir_Debug_regexp.obj) : error LNK2001: unresolved external symbol __std_init_once_link_alternate_names_and_abort
Important: When using the pre-built SDK 9.0.0 files, the problem does not show up. It starts with 9.1.0.
Steps to reproduce:
Either: Build your own project
- Create new project ("Console App") in Visual Studio 2019 (version 16.11.16)
- Project settings:
/MD
andx64
(both in Debug and Release) - Ensure project is including/linking to downloaded SDK 9.1.0 or 9.2.0
- Paste the code in the "Relevant Code" section below into the solution's
.cpp
file - Build (Platform=x64)
- When linking, the above errors will show up.
Or: Download a full Visual Studio 2019 solution
- Download the zipped solution (~500 MB, includes SDK files)
- Open
Firebase.sln
in Visual Studio 2019 - Set the
AppOptions
on line 57 - Build for platform
x64
- When linking, the above errors will show up.
- Switching the SDK versions: Edit
external\firebase\Import_Firebase.props
, line 5, to use versions 9.0.0, 9.1.0 and 9.2.0
Have you been able to reproduce this issue with just the Firebase C++ quickstarts ?
Yes and No. I used code from the Firestore quickstarter which directly led me to the problem. I didn't build the quickstarts directly.
What happened? How can we make the problem occur?
See above
Relevant Code:
#include "firebase/firestore.h"
#include "firebase/util.h"
int main()
{
// create app
firebase::App* _app = firebase::App::Create();
firebase::InitResult result;
// commenting out the following line will not produce the linker error
firebase::firestore::Firestore* _firestore = firebase::firestore::Firestore::GetInstance(_app, &result);
return 0;
}
Drive-by comment: Starting in v9.1.0, Windows builds must link against the bcrypt
and dbghelp
system libraries:
https://firebase.google.com/support/release-notes/cpp-relnotes#version_910_-_june_6_2022
Please check that you are linking against these libraries.
@dconeybe - yes I am. I figured out that one before. Also, that _CRT_SECURE_NO_WARNINGS
needs to be defined...
Hmm. A quick Google search surfaced this thread,
Hmm, a quick web search surfaced this thread, suggesting that it's a known issue:
https://developercommunity.visualstudio.com/t/-imp-std-init-once-complete-unresolved-external-sy/1684365
Does this help resolve your issue at all?
I have read the article before but it didn't help. Adding
#if _MSC_VER >= 1932 // Visual Studio 2022 version 17.2+
#pragma comment(linker, "/alternatename:__imp___std_init_once_complete=__imp_InitOnceComplete")
#pragma comment( \
linker, "/alternatename:__imp___std_init_once_begin_initialize=__imp_InitOnceBeginInitialize")
#endif
into my code does not change anything because my _MSC_VER
is 1929
(I'm using VS2019, not 2022)
Even applying the #pragma
statements without #if ... #endif
does not resolve the linker issue.
Dang. Okay, those are all of the ideas that I have. I'll back out of this issue now and let those with deeper knowledge than me comment.
We are seeing the same link errors (plus others) using the 9.5.0 pre-built binaries on Windows. We’ve tried building with VS 2019 and VS 2022, and get the same result.
We get the same unresolved symbol as in the original issue: __std_init_once_link_alternate_names_and_abort
Plus we get the following unresolved symbols: __std_find_trivial_1
and __std_find_trivial_4
.
We are just building a stripped-down test console app. This is the code in it’s entirety:
#include "firebase/firestore.h"
int main()
{
firebase::App *app = firebase::App::Create();
firebase::firestore::Firestore *db = firebase::firestore::Firestore::GetInstance();
return 0;
}
This compiles fine, but no matter what we do we get the above link errors.
Note that we are linking the x86
static libraries /MT
with all the required dependencies:
firebase_firestore.lib
firebase_auth.lib
firebase_app.lib
advapi32.lib
ws2_32.lib
crypt32.lib
rpcrt4.lib
ole32.lib
shell32.lib
bcrypt.lib
dbghelp.lib
We’ve tried everything but we can’t get even the above trivial test app to link!
Thanks for providing more information. Quick question to help us narrow this down a bit more: can you try reproducing this by initializing a different product other than Firestore? Auth for instance?
Thanks!
Hi @DellaBitta. Actually, we fixed the problem last night:-) Turns out there was a bug in the MSVC compiler!
According to this issue here, the bug was accidentally introduced recently, as a side-effect of fixing something else. The bug broke binary compatibility in the scenario where a VS 2022 app linked to prebuilt static libraries from an earlier version of VS. (E.g. Firebase SDK built with VS 2019.)
The bug has been fixed and the solution is to simply upgrade to the latest version of VS 2022, 17.3. All good now.
Cheers, Jarryl
Hi @JarrylWirth,
That's fantastic news. I'm glad that you're unblocked! I assume you're working with @christoph-nimagna, but just in case my assumptions aren't correct, @christoph-nimagna can you confirm that this issue is resolved?
Thanks!
@DellaBitta - I'm independent of @JarrylWirth ...
I updated to SDK 9.6.0 and tried with VS2022 17.3.6 which resolved the issue. I'll close it therefore.
Thanks everyone!
👍