C++ executable keep looking for ordinal entry point - c++

I have a C++ application with the below source code:
#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
int main(int argc, char** argv)
{
std::cout << "\nJust to be sure!" << std::endl;
// Making a connection to Mongo
mongocxx::instance instance{};
mongocxx::client client{mongocxx::uri{}};
// Access a database
mongocxx::database db = client["results"];
std::cout << "\ndone." << std::endl;
return 0;
}
I compile it using the below CMakeLists.txt file:
cmake_minimum_required(VERSION 3.7)
project(testing)
set(APP_SOURCES
test.cpp
)
link_directories(../../installed_mongocxx/lib)
add_executable(testapp ${APP_SOURCES})
target_link_libraries(testapp mongocxx bsoncxx)
target_include_directories(testapp PUBLIC
../../installed_mongocxx/include/mongocxx/v_noabi
../../installed_mongocxx/include/bsoncxx/v_noabi
E:/Softwares/Libraries/Boost/boost_1_64_0
)
install(TARGETS testapp
DESTINATION bin)
I compile the program using MSBuild on Windows 10 64bit without errors, and upon running it gives this error;
The ordinal 4694 could not be located in the dynamic library libmongoc-1.0.dll
Is there anything wrong with the C++ code or CMakeLists.txt that could be explanation of the error?

That's unlikely. The question is what .LIB file you're using to link the DLL. When you build a DLL, that also creates a small .LIB file. This is basically just a table of contents. If you mix the .LIB file from one build with the .DLL from another build, you may run into incompatibilities.
In this case, the .LIB file will be taken from ../../installed_mongocxx/lib, but the .DLL might not be. The DLL will be found at runtime, by Windows rules.

I notice that you've been asking a number of questions related to developing with mongocxx lately that all seem related. I encourage you to either ask a question on our mongodb-user Google Group or on our Jira project, which will make it easier for us to assist you in any follow-up questions you might have without needing to have a conversation in multiple places.
(Apologies for posting this as an answer rather than a comment; StackOverflow seems to have a length limit on comments, and I couldn't fit this in one)

Related

Compilation error after including jsoncpp

When I try to build test sources I get an error like after this.
stl_tree.h:542:14: error: ‘__node’ does not name a type
::new(__node) _Rb_tree_node<_Val>;
Executor's content.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
int main(int argc, char** argv) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(argc, argv);
}
My test' s source code starts with below includes.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
#include <iostream>
#include "common/data_util_astro_cfg.h"
TEST_GROUP(ASTRO_UTIL_TEST) {
void setup() { }
void teardown() { }
};
And the "common/data_util_astro_cfg.h" file has following includes.
#include "../data/data_type_file.h"
#include <json/json.h>
static AstroConfigs toAstroConfigs(std::string content)
My problem is I get compilation error with these includes, when I remove line json.h include everything is fine I can get binary output.
I think the problem is about new operator' s conflict. The solution is offered by Cpputest side and it is located on http://cpputest.github.io/manual.html#memory_leak_detection. But it isn't clear somehow. :(
The question has been already defined on Compilation error after including <map>. It is so similar to mine but the problem has solved with creating new project. In that case I have no option for that. I'm using Yocto project and the project has created with auto generation tools as well.
Can you help me on this? (Thank you for your time.)
Unfortunately, I solved the problem after a while. It seems something wrong with CPPUTest. At the top of the test file, I have several includes. Some of them belong to CPPUTest library, some of them are mine. My includes are following CPPUTest that's why I’m getting an error. If I changed their places, it would be working correctly. It seems meaningless, but it is the correct solution. ”PROBLEM SHOULD BE RESOLVED WITH DEFINE CPPUTEST LIBRARIES AT THE BOTTOM OF YOUR INCLUDE LIST.”

Struggling with dlib, linker errors and save_jpeg in XCode

First, I am new to C++ and dlib but I have successfully built the examples and started working on my own project. Things have been progressing smoothly until I try to save a jpeg. Attempting to compile code using dlib::save_jpeg throws a linker error and I cannot track down the solution. I have attempted to add #define DLIB_JPEG_SUPPORT above and below my #includes but no luck. I am using XCode and used cmake -G "Xcode" .. when I compiled the examples. Relevant code below. Since I am on a Mac, I have added header and library search paths for X11 (for dlib gui), OpenCV, and DLIB. I have libjpeg.dylib and linked that to my project with and without #define DLIB_JPEG_SUPPORT in main.cpp. Is there some other build setting I need to specify? Thank you in advance for your help.
Finally, I have seen other questions and pages about dlib and libjpeg issues but no luck yet. And yes I have source.cpp included in the project.
// the standard stuff
#include <string>
#include <iostream>
#include <unistd.h>
// opencv mat object
#include <opencv2/opencv.hpp>
// dlib>
#include <dlib/opencv.h>
#include <dlib/image_io.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_transforms.h>
int main(int argc, const char * argv[]) {
// retrieving images from a TCP connection
// decode data stream
img = cv::imdecode(rawImage, CV_LOAD_IMAGE_COLOR);
// perform image processing
dlib::cv_image<dlib::bgr_pixel> d_image(img);
// finally save the result to jpg
std::string fname = argv[1] + std::to_string(image_id) + ".jpg";
dlib::save_jpeg(d_image, fname); // <- line that won't compile
return 0;
}
After quit a bit of struggling and side-by-side comparisons I finally found the issue. In XCode go to to Build Settings and modify Other Linker Flags, Run Search Paths, and Other C++ Flags to match the compiled and working face_ex example. I wholesale copied all of those flags and included a missing libjpeg.dylib and was able to get things running. It should look something like this for the C++ flags . Hope this helps the next person.

Using Qt to configure OpenCV library failed

I'm new to Qt creator. Yesterday, I followed the official instructions to configure OpenCV library but it failed. I tried everything on the Internet but it just didn't work. Detailed are listed as belows:
test code is simple, I only want to ensure whether the library works:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello World!" << endl;
return 0;
}
My project configuration is like below :
I thought there might be a problem in debugger. I configure the debugger and I'm quite sure it's ok. The picture is here:
But it just doesn't work. When I click build and run, it says:
C1083: cannot open containing files: "opencv2/opencv.hpp": No such
file or directory.
What's strange is when I include <files> in the editor, the automatic code completion can detect the existence of the OpenCV library and hint after <opencv2/> that there are opencv.hpp, core.hpp .etc. and in the Include Hierarchy, the opencv.hpp exists.
So what might be the problem?

Using Boost library in XCode

not particularly good with this kind of stuff I have managed to install the Boost C++ library and this basic program works with the g++ compiler and linking to the right .dylib files.
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost;
int main()
{
filesystem::path path1("/Users/username/Documents/testfile.txt");
filesystem::remove(path1);
std::cout << "It worked" << std::endl;
return 0;
}
Now I would like to do the same, just using Xcode to build and run the program, but it doesn't work. I have done everything in this tutorial:
http://buddypanda.com/?p=10
i.e. include header and library search paths, as well as linked the .dylib files of filesystem and system under the 'Build Phases' tab.
The Build succeeds but then the program crashed with an error of EXC_BAD_ACCESS.
I can maybe provide more specifics on what goes wrong if you tell me where to look.
Thanks!
EDIT1: I am using g++-4.9 and Boost-1.58 and Xcode 6.4

mpf_set_d causes an illegal instruction in c++

I'm using GMP and getting an illegal instruction that I have found to be caused by mpf_set_d. I'm programming in Netbeans with cygwin in c++.
Thanks in advance!
Edit:
I have a folder containing the following files:
.dep.inc, cyggcc_s-seh-1.dll, cyggmp-10.dll, cyggmpxx-4.dll, cygstdc++-6.dll, cygwin1.dll, my executable, gmp.h, gmpxx.h, libgmp.a, libgmp.la, libgmp.lai, libgmp.lai, libgmp.libcmd, libgmpxx.a, libgmpxx.la, libgmpxx.lai, main.cpp, main.o, main.o.d, Makefile, text file needed for program and folders needed for program.
I have tried many things, one of which was to add an executable to this folder that ran the following code:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include "gmpxx.h"
#include <stdarg.h>
#include <string>
using namespace std;
int main()
{
mpf_t a;
mpf_init(a);
mpf_set_d(a,3.1415926535);
cout << "works" << endl;
}
Running this on my own computer with GMP installed gives me 'works' after which it closes, on another computer that does not have GMP installed it throws an error and closes. The error is an exception: status_illegal_instruction.
I can't give you my code but I can post snippets. Please tell me if more information is necessary!
Thanks again.
Edit 2:
The same counts for mpf_set_str as well as the c++ wrapper.