Mongocxx in Windows LNK2001: unresolved external symbol __imp_mongoc_read_prefs_new - c++

I have followed the instructions in the following document to the letter (including the instructions for building mongo-c-driver): https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
I am attempting to build the sample code provided (using VS2015), which I shall copy paste for convenience:
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{ mongocxx::uri{} };
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
I have specified the header and library include directories according to the project settings provided. I have also added the MONGOCXX_STATIC and BSONCXX_STATIC preprocessor definitions.
Initially I added the following libs to the linker settings: libmongocxx.lib;libbsoncxx.lib;mongoc-static-1.0.lib;bson-1.0.lib;
When compilation failed I tried using the static bson lib (not sure why the documentation suggests using the non-static one?), so my input libs are now as follows: libmongocxx.lib;libbsoncxx.lib;mongoc-static-1.0.lib;bson-static-1.0.lib;
Despite my best efforts, and frantic googling, I get around 2000 unresolved externals, an example of which I've copied and pasted below:
libmongocxx.lib(distinct.obj) : error LNK2001: unresolved external symbol __imp_mongoc_read_prefs_new
It appears as though it is coming from mongo c driver. I have seen this SO article, but I am already linking mongoc-static-1.0.lib as stated above - unfortunately there is little else to go on in this post. The compiler is clearly finding said lib (otherwise it would complain with "not found" errors), so I can only think that I have somehow built the lib incorrectly.
I'll also mention at this point that I have successfully built and run the code using the non-static libs and dlls - however, it is highly desirable to avoid having to use dlls and so I would like to use the static libs if possible.
I have read the installation instructions several times now, and something that sticks out at me is the following:
If you need static libraries, be sure to use the --enable-static configure option when building libmongoc.
However, this appears to be appropriate only for installing in Linux, I am installing in Windows using CMake. I ran CMake.exe -LH to see what available options there were in the hope of finding something about static libs, but no dice. It appears that there are no options necessary for building the static libs, since when I installed mongo-c-driver, I successfully obtained the bson-static-1.0.lib and mongoc-static-1.0 libs.
I find myself at a loss! Any help would be greatly appreciated, cheers.

Have you resolved the problems? I have similar problems. However, it seems fine if you use older drivers, like mongoc 1.4, bson 1.4 and mongocxx 3.0, though they can only support mongodb 3.2 and older

Related

Fatal Error: comdef.h: No such file or directory

I installed Aspose.Cells and tried to write a simple C++ file that includes Aspose.Cells.h. I soon realized that I had to install two other external libraries, boost and icu4c as without these libraries my compiler would throw errors saying some h or hpp files can not be found.
My problem is: even after I installed these libraries, I still couldn’t compile my code, as I received a new error saying “Fatal ERROR: comdef.h: No such file or directory.”
And the error persisted even after I installed the latest version for SDK for Win 10.
My simple file can run if I remove the line "#include Aspose.Cells.h" .
Can someone please enlighten me as to how to solve this error?
Also I noticed there is a folder called “Publish” under “include” folder for Aspose.Cells. This folder is besides boost and icu. Could this mean Publish is the third external library to be installed? But I couldn’t find any library called Public on the web. Pls see the screenshot below.
directory of include folder that comes with the installed Aspose.Cells package
Thanks a lot!
My code is as follows:
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "hello!!!" << endl;
return 0;
}
Regards
Hillary

dyld: Symbol not found: _PyBaseObject_Type

I'd like to use the Boost library in my C++ code, so I've inputted the right include search path and the right library search path, then I added all the Boost library files in Xcode. When I build my code the compiler says that the build is successful. However, once I run the code, the console tells this:
Console:
dyld: Symbol not found: _PyBaseObject_Type
Referenced from: /usr/local/lib/libboost_python27.dylib
Expected in: flat namespace
in /usr/local/lib/libboost_python27.dylib
Program ended with exit code: 9
My code:
#include <iostream>
#include <boost/any.hpp>
int main()
{
std::cout << std::endl;
return 0;
}
Where is my mistake? Please help.
This error occurs when you don't add a package to your project the right way. The problem has resolved in my example by installing Boost via Homebrew. Installing the package the right way means that if you install it manually (e.g. downloading it from GitHub), you should install it on the right path. But I suggest always installing C++ packages via Homebrew.

MongoDB C++ Driver (mongocxx) single unresolved external symbol (mongocxx::v_noabi::uri::k_default_uri) when running test after installation

For the past two days I have tried to build and test mongocxx on two different Windows 10 machines, one using VS2015 and the other using VS2017. The builds install without errors (though I had initial issues with ENABLE_EXTRA_ALIGNMENT). However, once I try to build the exact test code from the MongoDB installation guide (http://mongocxx.org/mongocxx-v3/installation/), I get the following linker error:
error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const mongocxx::v_noabi::uri::k_default_uri" (?k_default_uri#uri#v_noabi#mongocxx##2V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##B)
I have rebuilt with boost 1.59, boost 1.68, boost 1.70, and using C++17 with no boost.
I have tested from builds with mongocxx 3.4.0 with mongoc 1.14.0, and mongocxx 3.3.1 with mongoc 1.10.1, and this is always the error I end up at.
I know Visual Studio sees mongocxx.lib, because if I remove it I get a ton of linker errors instead of just one.
The one and ONLY way I got the test program to run was to build mongocxx with static libraries, and in the test program link them along with the shared libraries for the mongo c driver. However, that doesn't seem like the right solution because as the installation guide says:
Linking an application against both shared libmongoc and static
mongocxx is not supported, nor is linking against both static
libmongoc and shared mongocxx.
What is also annoying is that if I open up mongocxx.lib and search for "?k_default_uri#uri..." I find it. So its in there. But something is wrong apparently.
Note that if I comment out everything below the first line in the main function like so:
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
mongocxx::instance inst{};
/*
mongocxx::client conn{mongocxx::uri{}};
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
*/
}
Then it compiles and runs that part just fine.
It is specifically the "mongocxx::uri{}" part that it is unable to resolve
Is something being built as 32 bit that I don't realize? Or something being built in release mode that I don't realize? My mongocxx and mongo c builds all say Debug/64 bit, but maybe there is something I'm not seeing
Here are my cmake commands for the c driver and cxx driver respectively:
cmake -G "Visual Studio 15 2017 Win64" "-DCMAKE_BUILD_TYPE=Debug" "-DENABLE_EXTRA_ALIGNMENT=OFF" "-DCMAKE_INSTALL_PREFIX=C:\<path removed>\mongo-c-driver" "-DCMAKE_PREFIX_PATH=C:\<path removed>\mongo-c-driver" ..
cmake -G "Visual Studio 15 2017 Win64" "-DCMAKE_BUILD_TYPE=Debug" "-DBSONCXX_POLY_USE_BOOST=1" "-DCMAKE_INSTALL_PREFIX=C:\<path removed>\mongo-cxx-driver" "-DCMAKE_PREFIX_PATH=C:\<path removed>\mongo-c-driver" "-DBOOST_ROOT=C:\<path removed>\boost_1_68_0" ..
And after each of these I run the following:
msbuild.exe /p:Configuration=Debug ALL_BUILD.vcxproj
msbuild.exe /p:Configuration=Debug INSTALL.vcxproj
And these are the relevant properties from my VS project:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\libraries\boost_1_68_0;$(ProjectDir)..\..\..\libraries\mongo-cxx-driver\include\mongocxx\v_noabi;$(ProjectDir)..\..\..\libraries\mongo-c-driver\include\include\libmongoc-1.0;$(ProjectDir)..\..\..\libraries\mongo-c-driver\include\libbson-1.0;$(ProjectDir)..\..\..\libraries\mongo-cxx-driver\include\bsoncxx\v_noabi</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MONGOCXX_STATIC;BSONCXX_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(ProjectDir)..\..\..\libraries\boost_1_68_0\stage\lib;$(ProjectDir)..\..\..\libraries\mongo-c-driver\lib;$(ProjectDir)..\..\..\libraries\mongo-cxx-driver\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>mongocxx.lib;bsoncxx.lib;mongoc-static-1.0.lib;bson-1.0.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
The only relevant question I found on stackoverflow is this one: Compiler error with new MongoDB C++ driver and they concluded "It had to do with incorrectly compiled and installed libraries for bson and mongocxx". I can compile the libraries just fine, yet they still result in this error. So maybe I am compiling them incorrectly somehow? I'm truly lost, and the proof of this is that in years of programming this is the first time I have posted to stackoverflow.

Linker error LNK2019 when using DCMTK with Visual Studio

This is not a new question but the solutions haven't worked for me. I want to read dicom files using C++. I have 32-bit Windows PC with VS 2013 community edition.
This post and other answers therein suggested using DCMTK. I installed DCMTK (using CMake followed by VS) and configured it for use with VS using guidelines and links provided in this post. Then I wrote a simple test program and tried to compile it:
#include "stdafx.h"
#include "dcmtk\dcmdata\dctk.h"
#include "dcmtk\config\osconfig.h"
#include "dcmtk\dcmimgle\dcmimage.h"
#include <iostream>
using namespace std;
int main()
{
DicomImage *image = new DicomImage("test.dcm");
if (image != NULL)
{
if (image->getStatus() == EIS_Normal)
{
if (image->isMonochrome())
{
image->setMinMaxWindow();
Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */));
if (pixelData != NULL)
{
/* do something useful with the pixel data */
}
}
}
else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;
return 0;
}
Upon compilation, it gives the following error:
dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _Netbios#4 referenced in function "unsigned char * __cdecl getMACAddress(unsigned char * const)" (?getMACAddress##YAPAEQAE#Z)
This error seems to be common but none of the following solutions work for me:
FAQ#27 and another post of DCMTK forum: It suggests using particular order of lib files to be included. My order of including files is as follows (I tried the reverse order as well but it didn't work):
All of this doesn't work. In fact, I'm not sure which lib files are supposed to be included? How to decide that?
I've also included "C:\Program Files\DCMTK\lib" under additional library directories and "C:\Program Files\DCMTK\include" under additional include directories in project properties.
Another similar question at stackoverflow has not been answered. Comments suggest to re-run CMake by disabling DCMTK_OVERWRITE_WIN32_COMPILER_FLAGS. I didn't do it because the DCMTK help page says don't disable this unless you really know what you're doing.
Can someone please guide?
The NetBios function resides in NETAPI32.LIB, so you can try moving NetAPI32.lib (which is in your list) to the top of that list.
Not sure which version of the DCMTK you use, but for the current development snapshot you need the following standard libraries (on Windows): "ws2_32 netapi32 wsock32". This information can be found in DCMTK's CMake files. By the way, you don't seem to use CMake for your project, right?
I think you misspelled dcmsign.lib as dcmsig.lib.
If changing that doesn't fix it, I would suggest the following order based on the support page that you linked to:
NetAPI32.lib
WSock32.lib
ofstd.lib
oflog.lib
dcmdata.lib
dcmsign.lib
dcmnet.lib
dcmsr.lib
dcmqrdb.lib
dcmtls.lib
dcmwlm.lib
dcmimgle.lib
dcmpstat.lib
dcmjpls.lib
dcmjpeg.lib
dcmimage.lib
ijg16.lib
ijg12.lib
ijg8.lib
I think that in this list, each library has to come after all the libraries that it depends on.
check your .lib and vs platform if the same ,such lib for x64, then your vs platform must be x64.
I had the same error. You can go to project properties-> linker -> input -> Additional Dependencies-> Edit -> add these two libraries-( netapi32.lib,wsock32.lib) before all other libraries . This solved the error for me .

CGAL unresolved externals when compiling/linking on Windows

I'm getting strange (for me) errors during compiling a test program which uses some parts of the CGAL library.
First, the environment:
Windows 7 64 bits
Boost 1.53
CGAL 4.3
Qt 4.8.4
CMake 2.8.10.2
Visual Studio 2010 professional
I installed all the libraries for 32 bits (if this was an option during installation).
Installation wrong?
In order to install CGAL on my computer, I followed this tutorial: http://www.cgal.org/windows_installation.html. I have to note here that this did not work out-of-the-box for me. During the configuration phase of CGAL in CMake, the boost libraries were not found (although I set the corresponding environment variables, as stated in the tutorial). After setting the incorrect variables in CMake, I was able to complete the configuration and generation phase. After that, I was able to compile both the Debug as well as the Release configurations of CGAL in Visual Studio.
In order to test whether the CGAL lib was installed successfully, I tried to compile and run both the examples and demos. These also did not work immediately. The problem was that the CGAL and Boost headers (and binaries) were not found. After setting the right paths in Project properties => Configuration properties => C/C++ => Additional Include Directories and in Project properties => Configuration properties => Linker => Additional Library Directories the examples and demos could be build. I successfully ran these examples after that.
Actual problem
Now, I'm tyring to compile a simple program, in order to be able to make a certain exercise (http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2 exercise 2.1). Here, there are two files supplied: basic_typdef.h and cgal_bootcamp.cpp
*basic_typedef.h*
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
/*******************************************************************************************
* This file contatins basic typedefs (from CGAL and more).
*******************************************************************************************/
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
typedef std::list<Polygon_with_holes> Polygon_with_holes_container;
*cgal_bootcamp.cpp*
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
return 0;
}
(For convenience I removed the comments in the file cgal_bootcamp.cpp)
With Visual Studio, I can compile the two files as above. However, when I try to create a Point (as defined in basic_typedef.h), I'm getting the (strange) errors:
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
/*
1. Point
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Point_2.html
*/
// Create Point with the coordinates (0.5, 0.6)
Point p;
return 0;
}
The errors that occur:
Error 1 error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 2 error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 3 error LNK1120: 2 unresolved externals C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\Debug\warmup-exercise.exe 1 1 warmup-exercise
4 IntelliSense: #error directive: "Mixing a dll CGAL library with a static runtime is a really bad idea..." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 364 4
5 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 397 4
I have no clue what is going wrong here (I have to note that I'm still a noob with C++). It seems that there is something wrong with the GMP library (at least the linking to this?) I found in another post that for someone there were no libgmp files build (can't find that post anymore), but that is not the case for me (I think): in CGAL-4.3/auxiliary/gmp/lib I see four files, libgmp-10.dll libgmp-10.lib libmpfr-4.dll and libmpfr-4.lib.
Also the error on line 4 points to something that might cause this error ("Mixing a dll CGAL library with a static runtime is a really bad idea..."), but I do not know what this actually means (or how I can resolve it).
Further, I tried to setup all the libraries on another computer, but I got the same errors there also.
Could anyone point me in the right direction to solve this problem? If you need more information, please let me know.
This comment answered the question: the script cgal_create_cmake_script can be used to create a CMake file that can be used to generate a correct Visual Studio project using CGAL.