Mongo-c-driver in Windows LNK2019 unresolved external symbol __imp___getpid referenced in function _mongoc_log

319 views
Skip to first unread message

Jay

unread,
Oct 2, 2017, 4:31:44 PM10/2/17
to mongodb-user
I've been following this documentation https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation to setup a C++ application with mongDB.

The pre-existing application is a Win32 DLL project to be used with SierraChart https://www.sierrachart.com/index.php?page=doc/UsingVisualCPlusPlus.php#CreateProject. I've previously integrated UnQlite into the application but it's time to convert to something a little more cloud friendly.  

I've installed libbson, mongo-c-driver and mongo-cxx-driver via the following:

Installing Libbson:

cd libbson-1.8.0
cmake
-G "Visual Studio 15" "-DCMAKE_INSTALL_PREFIX=C:\libbson"
-- Output --
-- The C compiler identification is ;MSVC 19.11.25508.2
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
Current version (from VERSION_CURRENT file): 1.8.0
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for snprintf
-- Looking for snprintf - found
-- Looking for reallocf
-- Looking for reallocf - not found
-- Performing Test BSON_HAVE_TIMESPEC
-- Performing Test BSON_HAVE_TIMESPEC - Success
--     struct timespec found
-- Looking for gmtime_r
-- Looking for gmtime_r - not found
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jay/Downloads/libbson-1.8.0

I Set all libbson projects to MTd (debug) and MT (release)
Build ALL_BUILD using Visual Studio
Build INSTALL using Visual Studio

Installing Mongo C Driver:

cd .\mongo-c-driver-1.8.0
cmake
-G "Visual Studio 15" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" "-DENABLE_SSL=WINDOWS" "-DENABLE_SASL=SSPI" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_PREFIX_PATH=C:\libbson" "-DENABLE_STATIC=YES" "-DENABLE_TESTS=NO"
--- Output ---
-- The C compiler identification is ;MSVC 19.11.25508.2
-- The CXX compiler identification is ;MSVC 19.11.25508.2
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Current version (from VERSION_CURRENT file): 1.8.0
-- Searching for libbson CMake packages
--   libbson found version "1.8.0"
--   libbson include path "C:/libbson/include/libbson-1.0"
--   libbson libraries "C:/libbson/lib/bson-1.0.lib"
-- Looking for ASN1_STRING_get0_data in ssl
-- Looking for ASN1_STRING_get0_data in ssl - not found
-- Looking for include file strings.h
-- Looking for include file strings.h - not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Compiling against Secure Channel
-- Compiling against Windows SSPI
-- Looking for include file byteswap.h
-- Looking for include file byteswap.h - not found
-- Looking for include file dlfcn.h
-- Looking for include file dlfcn.h - not found
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Looking for include file memory.h
-- Looking for include file memory.h - found
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for include file string.h
-- Looking for include file string.h - found
-- Looking for include file sys/byteswap.h
-- Looking for include file sys/byteswap.h - not found
-- Looking for include file sys/endian.h
-- Looking for include file sys/endian.h - not found
-- Looking for include file sys/mman.h
-- Looking for include file sys/mman.h - not found
-- Looking for include file sys/resource.h
-- Looking for include file sys/resource.h - not found
-- Looking for include file sys/stat.h
-- Looking for include file sys/stat.h - found
-- Looking for include file sys/time.h
-- Looking for include file sys/time.h - not found
-- Looking for include file unistd.h
-- Looking for include file unistd.h - not found
-- Looking for include file windows.h
-- Looking for include file windows.h - found
-- Performing Test HAVE_BUILTIN_EXPECT
-- Performing Test HAVE_BUILTIN_EXPECT - Failed
-- Performing Test HAVE_BUILTIN_CTZ
-- Performing Test HAVE_BUILTIN_CTZ - Failed
-- Enabling snappy compression (bundled)
-- Enabling zlib compression (bundled)
-- Looking for include file stdarg.h
-- Looking for include file stdarg.h - found
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
CMake Warning:
 
Manually-specified variables were not used by the project:


    CMAKE_BUILD_TYPE




-- Build files have been written to: C:/Users/jay/Downloads/mongo-c-driver-1.8.0


I Set all mongo-c-driver projects to MTd (debug) and MT (release)
Build ALL_BUILD using Visual Studio
Build INSTALL using Visual Studio

Installing MongoCXX Driver:

cd .\mongo-cxx-driver-r3.1.3
cmake
-G "Visual Studio 15" -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver -DCMAKE_PREFIX_PATH=c:\mongo-c-driver -DBOOST_ROOT=C:\local\boost_1_65_1 -DLIBBSON_DIR=C:\libbson -DLIBMONGOC_DIR=C:\mongo-c-driver -DBUILD_SHARED_LIBRARIES=OFF
--- Output ---
-- The CXX compiler identification is MSVC 19.11.25508.2
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- No build type selected, default is Release
-- The C compiler identification is MSVC 19.11.25508.2
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found LIBBSON: bson-1.0
-- Boost version: 1.65.1
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Found LIBMONGOC: mongoc-1.0
-- Configuring done
-- Generating done
CMake Warning:
 
Manually-specified variables were not used by the project:


    BUILD_SHARED_LIBRARIES




-- Build files have been written to: C:/Users/jay/Downloads/mongo-cxx-driver-r3.1.3


I Set all mongocxx projects to MTd (debug) and MT (release)
Build ALL_BUILD using Visual Studio
Build INSTALL using Visual Studio

I then updated my project with the following setting:

Debugging > Environment:
PATH=C:\mongo-c-driver\bin
PATH=C:\libbson\bin
PATH=C:\mongo-cxx-driver\bin

C\C++ > General > Additional Include Directories:
C:\local\boost_1_65_1;C:\mongo-cxx-driver\include\mongocxx\v_noabi;C:\mongo-cxx-driver\include\bsoncxx\v_noabi;C:\mongo-c-driver\include\libmongoc-1.0;C:\libbson\include\libbson-1.0;%(AdditionalIncludeDirectories)

C\C++ > General > Additional #using Directories:
C:\mongo-c-driver\lib;c:\mongo-cxx-driver\lib\;%(AdditionalUsingDirectories)

C\C++ > Preprocessor > Preprocessor Definitions:
WIN32;MONGOCXX_STATIC;BSONCXX_STATIC;_DEBUG;_CONSOLE;<different options>

C\C++ > Code Generation > Runtime Library:
Debug Multi-threaded Debug (/MTd)
Release Multi-threaded (/MT)

C\C++ > Precompiled Headers > Precompiled Header:
Not Using Precompiled Headers

Linker > General > Additional Library Includes:
C:\libbson\lib;C:\mongo-cxx-driver\lib;C:\mongo-c-driver\lib;%(AdditionalLibraryDirectories)

Linker > Additional Dependencies:
libmongocxx.lib;libbsoncxx.lib;mongoc-static-1.0.lib;bson-static-1.0.lib;ws2_32.lib;Secur32.lib;Crypt32.lib;BCrypt.lib;legacy_stdio_definitions.lib;%(AdditionalDependencies)

Here is the database.cpp I have added to be included in the existing project:

#include "database.h"


#include <cstdlib>
#include <iostream>
#include <string>


#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>


#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/options/client.hpp>
#include <mongocxx/uri.hpp>


/**
 * Class constructor.
 */

Database::Database()
{
}


/**
 * Class destructor.
 */

Database::~Database()
{
}


/**
 * Connects to the Database instance.
 */

void Database::Connect()
{
 
using bsoncxx::builder::stream::document;


 mongocxx
::instance inst{};
}




The following are the errors I get when I attempt to build the solution:

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp___getpid referenced in function _mongoc_log StorageConnect E:\Trading\SierraChartStudies\SwingStudy\StorageConnect\mongoc-static-1.0.lib(mongoc-log.obj) 1
Error LNK2019 unresolved external symbol __imp___localtime64_s referenced in function _localtime_s StorageConnect E:\Trading\SierraChartStudies\SwingStudy\StorageConnect\mongoc-static-1.0.lib(mongoc-log.obj) 1
Error LNK2019 unresolved external symbol __except_handler4_common referenced in function __except_handler4 StorageConnect E:\Trading\SierraChartStudies\SwingStudy\StorageConnect\MSVCRTD.lib(_chandler4gs_.obj) 1
Error LNK1120 3 unresolved externals StorageConnect E:\Trading\Data\SierraCharts\StorageConnect.dll 1


Initially it appears as though it's similar to https://jira.mongodb.org/browse/CDRIVER-2054 which was solved with an update to libmongoc where __declspec(dll*) was being added to all API function declarations unconditionally.

Any help on this would be greatly appreciated. Hopefully it's something small I've missed with the initial setup.

Andrew Morrow

unread,
Oct 11, 2017, 11:55:31 AM10/11/17
to mongod...@googlegroups.com

Hi - 

I have a theory about this, after thinking about it for some time now.

You said that you are setting "all ... projects to MTd and MT". That implies two different builds. But the target library names don't vary with those settings. Are you installing the resulting binaries to the same place? Do you think you may have overwritten the MTd builds of one driver (c or c++) with MT builds, thus resulting in a binary directory that has mixed runtime linkage?

I'd propose that you build and install the MT and MTd versions of mongo-c-driver and mongo-cxx-driver to different locations.

Eventually, I would like to see both the C driver and C++ driver use boost like ABI tagging in the filename to avoid exactly this issue (and, while we are at it, use #pragma comment to auto-inject the library name).

Could you retry your build, using only one mode (e.g. MT or MTd) consistently for all builds (c driver, c++ driver, application) and see if the issues go away?

Thanks,
Andrew


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/5d42ca9b-a61b-4887-a1ef-229c4e897b58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Jay

unread,
Oct 16, 2017, 5:24:05 PM10/16/17
to mongodb-user
Thanks for the help on this one Andrew!

You were right, there was incorrect linkage occurring with the build path. Even though I had updated the runtime libraries to be used, I was still building to the same target directory and it was preventing the updated binaries to be built and installed. All projects are building as expected now. Greatly appreciate the help.

Andrew Morrow

unread,
Oct 16, 2017, 11:14:20 PM10/16/17
to mongod...@googlegroups.com

Great! I'm happy to hear that my guess proved helpful. Hopefully we will do ABI tagging and auto-linking sometime soon and this will all get simpler.

On Mon, Oct 16, 2017 at 5:24 PM, Jay <jayt...@gmail.com> wrote:
Thanks for the help on this one Andrew!

You were right, there was incorrect linkage occurring with the build path. Even though I had updated the runtime libraries to be used, I was still building to the same target directory and it was preventing the updated binaries to be built and installed. All projects are building as expected now. Greatly appreciate the help.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

Reda Bousbah

unread,
Dec 12, 2017, 7:03:28 AM12/12/17
to mongodb-user
Hello,
I am currently facing the same problem, but I  can't figure out how to fix it.
What are the practical steps you did to solve it?

Thaaaank you


On Tuesday, 17 October 2017 05:14:20 UTC+2, acm wrote:

Great! I'm happy to hear that my guess proved helpful. Hopefully we will do ABI tagging and auto-linking sometime soon and this will all get simpler.
On Mon, Oct 16, 2017 at 5:24 PM, Jay <jayt...@gmail.com> wrote:
Thanks for the help on this one Andrew!

You were right, there was incorrect linkage occurring with the build path. Even though I had updated the runtime libraries to be used, I was still building to the same target directory and it was preventing the updated binaries to be built and installed. All projects are building as expected now. Greatly appreciate the help.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

Wan Bachtiar

unread,
Dec 19, 2017, 11:55:52 PM12/19/17
to mongodb-user

I am currently facing the same problem, but I can’t figure out how to fix it.

Hi Reda,

Could you please open a new discussion thread along with the following details:

  • libbson version, installation command and output.
  • mongo-c-driver version, installation command and output.
  • mongo-cxx-driver version, installation command and output.
  • Any error message that you’re getting.
  • Any additional details, i.e. PATHs, etc.

This would make it easier for someone to help debug the problem.

What are the practical steps you did to solve it?

Based on the discussion above , a retry of the build using only one mode (e.g. MT or MTd) consistently for all builds (c driver, c++ driver, application) solved the problem.

Kind regards,
Wan.

Reply all
Reply to author
Forward
0 new messages