Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3236

Fix libbson/libmongoc API export decorations

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: libbson, libmongoc
    • Labels:
      None

      Description

      The work being done for CDRIVER-3047 requires updates to the CMake configurations of both libbson and libmongoc. In the process of implementing the necessary changes an unexpected build failure began to occur:

      [2019/07/11 20:06:04.710] ClCompile:
      [2019/07/11 20:06:04.710]   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /c /I"C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\install-dir\include\libbson-1.0" /Zi /nologo /W3 /WX- /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"hello_bson.dir\Debug\\" /Fd"hello_bson.dir\Debug\vc140.pdb" /Gd /TC /errorReport:queue C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\hello_bson.c
      [2019/07/11 20:06:04.932]   hello_bson.c
      [2019/07/11 20:06:04.932] Link:
      [2019/07/11 20:06:04.932]   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\Debug\hello_bson.exe" /INCREMENTAL /NOLOGO "C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\install-dir\lib\bson-static-1.0.lib" ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/data/mci/ac163b4f77d3f3b3f2a2bcf58b02f0e1/mongoc/src/libbson/examples/cmake/find_package_static/Debug/hello_bson.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/data/mci/ac163b4f77d3f3b3f2a2bcf58b02f0e1/mongoc/src/libbson/examples/cmake/find_package_static/Debug/hello_bson.lib" /MACHINE:X64  /machine:x64 hello_bson.dir\Debug\hello_bson.obj
      [2019/07/11 20:06:04.966] hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_free referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.966] hello_bson.obj : error LNK2019: unresolved external symbol __imp_bcon_new referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.966] hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_bcon_magic referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.966] hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_destroy referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.966] hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_as_canonical_extended_json referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.966] C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\Debug\hello_bson.exe : fatal error LNK1120: 5 unresolved externals [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999] Done Building Project "C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj" (default targets) -- FAILED.
      [2019/07/11 20:06:04.999] Done Building Project "C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\ALL_BUILD.vcxproj" (default targets) -- FAILED.
      [2019/07/11 20:06:04.999] Build FAILED.
      [2019/07/11 20:06:04.999] "C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\ALL_BUILD.vcxproj" (default target) (1) ->
      [2019/07/11 20:06:04.999] "C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj" (default target) (3) ->
      [2019/07/11 20:06:04.999] (Link target) ->
      [2019/07/11 20:06:04.999]   hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_free referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999]   hello_bson.obj : error LNK2019: unresolved external symbol __imp_bcon_new referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999]   hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_bcon_magic referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999]   hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_destroy referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999]   hello_bson.obj : error LNK2019: unresolved external symbol __imp_bson_as_canonical_extended_json referenced in function main [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999]   C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\Debug\hello_bson.exe : fatal error LNK1120: 5 unresolved externals [C:\data\mci\ac163b4f77d3f3b3f2a2bcf58b02f0e1\mongoc\src\libbson\examples\cmake\find_package_static\hello_bson.vcxproj]
      [2019/07/11 20:06:04.999]     0 Warning(s)
      [2019/07/11 20:06:04.999]     6 Error(s)
      

      The failure appeared to correlate with the symbols that are referenced from within hello_bson.c. Based on that, I attempted the following change:

      diff --git a/src/libbson/src/bson/bson-macros.h b/src/libbson/src/bson/bson-macros.h
      index e2f09f013..7494fbd19 100644
      --- a/src/libbson/src/bson/bson-macros.h
      +++ b/src/libbson/src/bson/bson-macros.h
      @@ -84,7 +84,7 @@
       #elif defined(BSON_COMPILATION)
       #define BSON_API __declspec(dllexport)
       #else
      -#define BSON_API __declspec(dllimport)
      +#define BSON_API __declspec(dllexport)
       #endif
       #define BSON_CALL __cdecl
       
      diff --git a/src/libmongoc/src/mongoc/mongoc-macros.h b/src/libmongoc/src/mongoc/mongoc-macros.h
      index 62f106a8a..284f5ae2f 100644
      --- a/src/libmongoc/src/mongoc/mongoc-macros.h
      +++ b/src/libmongoc/src/mongoc/mongoc-macros.h
      @@ -38,7 +38,7 @@
       #elif defined(MONGOC_COMPILATION)
       #define MONGOC_API __declspec(dllexport)
       #else
      -#define MONGOC_API __declspec(dllimport)
      +#define MONGOC_API __declspec(dllexport)
       #endif
       #define MONGOC_CALL __cdecl
      

      That caused the failure to go away, but after asking input from some other team members it was recommended to use CMake's GenerateExportHeader instead of the manual configuration that is currently in place.

      This ticket involves a thorough investigation of the failure to ensure a complete understanding of why the failure was not evident prior to the CDRIVER-3047 change, followed by the recommended migration to CMake's GenerateExportHeader.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                roberto.sanchez Roberto Sanchez
                Reporter:
                roberto.sanchez Roberto Sanchez
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: