mongocxx::client() if it is valid, before calling the function? std::cout << "Build MongoDB-Uri: " << strMongoDbUri << std::endl;
// Output: Build MongoDB-Uri: mongodb://conversion-server:my-pa...@127.0.0.1:27017/MyDatabase
try{
auto blubb = mongocxx::uri(strMongoDbUri); // blubb for figuring out in which function the error occured...
// in this line the error occured
conn = mongocxx::client(blubb);==9537== Invalid read of size 8
==9537== at 0x4A0E9E: _mongoc_client_new_from_uri (in /Static/MyBinary)
==9537== by 0x463B05: mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&) (in /Static/MyBinary)
==9537== by 0x44DF0C: CMongo::CMongo() (CMongo.cpp:61)
...callstack
==9537== by 0x4152B4: CThread::run() (CThread.cpp:223)
==9537== Address 0xe0 is not stack'd, malloc'd or (recently) free'd
==9537==
==9537==
==9537== Process terminating with default action of signal 11 (SIGSEGV)
==9537== Access not within mapped region at address 0xE0
==9537== at 0x4A0E9E: _mongoc_client_new_from_uri (in /Static/MyBinary)
==9537== by 0x463B05: mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&) (in /Static/MyBinary)
==9537== by 0x44DF0C: CMongo::CMongo() (CMongo.cpp:61)
...callstack
==9537== by 0x4152B4: CThread::run() (CThread.cpp:223)
==9537== If you believe this happened as a result of a stack
==9537== overflow in your program's main thread (unlikely but
==9537== possible), you can try to increase the size of the
==9537== main thread stack using the --main-stacksize= flag.
==9537== The main thread stack size used in this run was 8388608.Invoking: GCC C++ Compiler
g++ -std=c++0x -DMONGOCXX_STATIC -DBSONCXX_STATIC -DMONGOC_STATIC -DBSON_STATIC -I"/StaticLibaries/include" -I"/StaticLibaries/include/bsoncxx/v_noabi" -I"/StaticLibaries/include/mongocxx/v_noabi" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/app/timer/CTimerComponent.d" -MT"src/app/timer/CTimerComponent.o" -o "src/app/timer/CTimerComponent.o" "../src/app/timer/CTimerComponent.cpp"
Building target: MyBinary
Invoking: GCC C++ Linker
g++ -L"/home/lambda/blinkit_CServ/StaticLibaries/lib" -o "MyBinary" ./src/base/allMyOfiles.o -lmongocxx -lbsoncxx -lmongoc-1.0 -lssl -lcrypto -lbson-1.0 -lPocoNet -lPocoFoundation -ldl -lrt -lcurl -lpthread
c libs with ./configure --disable-automatic-init-and-cleanup --enable-static --prefix=/my/own/folder/StaticLibaries --with-libbson=bundled
c++ libs with -DBSONCXX_POLY_USE_MNMLSTC=1 (at least it tried to downloade something from gitlab)
cmake -DLIBMONGOC_DIR:STRING="/my/own/folder/StaticLibaries" -DBUILD_SHARED_LIBS:BOOL="0" -DLIBBSON_DIR:STRING="/my/own/folder/StaticLibaries" -DCMAKE_INSTALL_PREFIX:PATH="/my/own/folder/StaticLibaries" ..
Build configuration:
Enable debugging (slow) : no
Enable extra alignment (required for 1.0 ABI) : yes
Compile with debug symbols (slow) : no
Enable GCC build optimization : yes
Code coverage support : no
Cross Compiling : no
Big endian : no
Link Time Optimization (experimental) : no
Documentation:
man : no
HTML : no
libmongoc 1.6.3 was configured with the following options:
Build configuration:
Enable debugging (slow) : no
Compile with debug symbols (slow) : no
Enable GCC build optimization : yes
Enable automatic init and cleanup : no
Enable maintainer flags : no
Code coverage support : no
Cross Compiling : no
Fast counters : no
Shared memory performance counters : yes
SASL : no
SSL : openssl
Libbson : bundled
--with-libbson=bundled VERSION_MONGOC=1.6.3
VERSION_MONGOCXX=3.1.1
UBUNTU=16.04
cd ${LOCAL_DIR}/mongo-c-driver-${VERSION_MONGOC}
./configure \
--disable-automatic-init-and-cleanup \
--prefix=${THE_LIB_DIR} \
--with-libbson=bundled
make -j4
make install
cd ${LOCAL_DIR}/mongo-cxx-driver-r${VERSION_MONGOCXX}
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${THE_LIB_DIR} \
-DLIBBSON_DIR=${THE_LIB_DIR} \
-DLIBMONGOC_DIR=${THE_LIB_DIR}
make -j4
make installvalgrind output:
==23948== Invalid read of size 8
==23948== at 0x839D4B6: _mongoc_client_new_from_uri (in /usr/local/lib/libmongoc-1.0.so.0.0.0)
==23948== by 0x5A0C527: mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&) (in /usr/local/lib/libmongocxx.so.3.1.1)
... Callstack
==23948== by 0x4124D4: CThread::run() (CThread.cpp:223)
==23948== Address 0x60 is not stack'd, malloc'd or (recently) free'd
./configure of mongo-c
Build configuration:
Enable debugging (slow) : no
Compile with debug symbols (slow) : no
Enable GCC build optimization : yes
Enable automatic init and cleanup : no
Enable maintainer flags : no
Code coverage support : no
Cross Compiling : no
Fast counters : no
Shared memory performance counters : yes
SASL : no
SSL : openssl
Libbson : system
Documentation:
man : no
HTML : no
--disable-automatic-init-and-cleanupmongocxx::instance instance{};
This will initialize everything, and must be called exactly once and must be available through the lifetime of your mongocxx use.
See https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/tutorial/#make-a-connection
-Hannes
'instance'. Might be the reason of this trouble. Will do better.
class MyMongoClass{
CMongo();
mongocxx::client conn;
class mongocxx::collection collTasks;
}
MyMongoClass::MyMongoClass(){
std::string MyUriString= .........;
auto blubb = mongocxx::uri(strMongoDbUri);
conn = mongocxx::client(blubb);
//conn = mongocxx::client(mongocxx::uri(strMongoDbUri));
collJobs = conn[MyConfiguration.databaseName][MyConfiguration.collJobs];
}