Open ssooffiiaannee opened 2 days ago
Does installing and using CMake module from installation work?
what do you mean by "CMake module from installation " ? I used to following instructions
$ git clone -b main https://github.com/pocoproject/poco.git
$ cd poco
$ mkdir cmake-build
$ cd cmake-build
$ cmake ..
$ cmake --build . --config Release
I used cmake v3.30.3 The build went fine, no errors in sight, the libraries have been built, cmake-build\lib\PocoFoundation.lib and PocoMongoDB.lib are there. But somehow it is loooking for PocoFoundationmt.lib which cannot be found anywhere.
You wrote above that you did not install.
Install Poco to some directory:
cmake --install . --prefix "SOME DIR"
Then use CMake find_package(Poco)
in your example instead of setting include path and linking directly.
That is the supported way and should work.
Another option for simple examples like yours is to define POCO_NO_AUTOMATIC_LIBS
on the command line.
Now that I managed to build Poco, and link it to my example code, the DB is not added after running the executable, no error reported, the server is running in localhost:default port, and I launched a nodejs app that writes into the db, and It worked, so the problem is not in the server side.
I am not sure what went wrong, I can't find any doc about this.
#include <Poco/MongoDB/Connection.h>
#include <Poco/MongoDB/Database.h>
#include <Poco/MongoDB/Document.h>
#include <Poco/MongoDB/Array.h>
#include <Poco/MongoDB/QueryRequest.h>
#include <Poco/MongoDB/ResponseMessage.h>
#include <iostream>
#include <string>
int main() {
Poco::MongoDB::Connection connection("127.0.0.1", 27017);
Poco::MongoDB::Database db("test_db");
std::string collectionName = "test_collection";
auto insertRequest = db.createInsertRequest(collectionName);
Poco::MongoDB::Document::Ptr doc = new Poco::MongoDB::Document();
doc->add("name", "John Doe");
doc->add("age", 30);
doc->add("email", "something@gmail.com");
insertRequest->documents().push_back(doc);
connection.sendRequest(*insertRequest);
std::cout << "Document inserted successfully!" << std::endl;
return 0;
}
TCP traffic capture shows TCP handshakes and insertion request submitted.
Use the function that captures the response and then print it. See unit tests.
Os : Windows 11 MSVC 2017
Goal: Make a minimum working example of a MongoDB client writing to a DB (make it compile at least, then make it work)
Code example :
Command line used : I have cloned the project to : D:\poco I have built the project in D:\poco\cmake-build folder I did not install, I'd rather link to the build folder
"C:\path\to\mvs\2017\Community\Common7\Tools\VsDevCmd.bat"
"C:\path\to\mvs\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe" /std:c++17 /EHsc \mongodb_testing.cpp /I"D:\poco\MongoDB\include" /I"D:\poco\Net\include" /I"D:\poco\Foundation\include" /link "D:\poco\cmake-build\lib\PocoFoundation.lib"
Error:
I can't find the PocoFoundationmt lib after the build, I don't know why it is trying to link to a non-existant library