How to implement a github C++ library? - c++

I am trying to use G+smo library from github. I download, unzip it and make. Then I could run all examples in the package. But there is no tutorial that guide me to build my own cpp file. For example I tried to build the simplest code from the tutorial:
# include <gismo.h>
using namespace gismo;
int main(int argc, char* argv[])
{
gsInfo << "Hello G+Smo.\n";
real_t a = 2.0; // a real number, ie. double
index_t b = 3; // an integer, ie. int
GISMO_ASSERT( a*b == 6, "This is an error, 2*3 should be 6.");
return 0;
}
And linked the lib file by -lgismo, but it says 'gismo.h: No such file or directory
compilation terminated'. I know it my be the fact that I am not familiar with c++. Can you guys give me some suggestion about it? Or, if it is overly obvious, can you just suggest me some book to read?
Thank you.

The error 'gismo.h: No such file or directory compilation terminated.' suggests that you didn't set the path where the compiler should look for the library headers. Try adding -I/path/to/gismo/headers to the compiler flags, e.g. on my system make install by default installed it to /usr/local/include/gismo so I have to add -I/usr/local/include/gismo.
By the way, there is a "tutorial": The README.txt in the deploy folder.

Related

libclang not finding headers in <> brackets on Mac with Xcode

Edit:
This program compiles. It's only when run does it fail to find iostream. I'm using the libclang.dylib that is bundled with Xcode.
I've written a small tool to begin working with libclang. I'm trying to parse TranslationUnits. The following program is saved in the file tool.cpp. Once compiled and run, it tries to parse tool.cpp as a TU. It's failing to get a clean run with default headers as it cannot find iostream on my Mac. After several attempts to supply arguments that point to the file, it still doesn't work. Any ideas?
#include "tool.h"
#include <iostream>
int main(int argc, char* argv[]) {
CXIndex index = clang_createIndex(0,0);
const char *args[] = {
"-I/usr/include",
"-I/usr/local/include",
"-I.",
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
//Should be here
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
}
;
Output:
tool.cpp 6:10: 'iostream' file not found
I've got the same issue. I am trying to add CPP to iOS Objective-C. It's not working. I found that this is about next "pain" from Apple because they do not use standard C++ library anymore. I've tried everything that mentioned on this site but haven't found any solution:

CImg Compilation Error: t_normal not in global namespace

I'm currently working on a class assignment that requires the use of the CImg library. To be clear, the assignment is not linking the library into the program; The class is using it access the pixel data for later use in the heart of the assignment.
I'm working in Xcode (OS X 10.10). CImg (2.2.2) is installed from homebrew, and I've managed to navigate the weird way Xcode deals with search paths (added the header to the section), and have successfully-ish included CImg.
my full code is as below.
#include <iostream>
#define cimg_display 0 //I don't need X11 at all
#include "CImg.h"
using namespace cimg_library;
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
However, I get 17 Compile-time errors from CImg.h, which are very unusual, and all of the form:
"No member named 't_normal' in the global namespace; did you mean simply 't_normal'?"
Thinking I might have received a bad download, I have attempted to redownload CImg, with no luck. I have also gotten to this same point with non-homebrew versions of CImg.
To verify the download, I also compiled the examples from the command line and they ran perfectly.
Is there a problem with CImg that I'm not aware of, a problem with Xcode that I'm not aware of, or is there something fundamental that I'm missing (definitely an option, my C-style programming is a little rusty) ?
halp pls.
Your code runs fine if you do this:
Create a new Xcode project, with:
type = "Command Line Tool"
language = "C++"
Then go to "Build Settings" and add the path to the directory containing CImg.h to your "User Header Search Paths"

How to use GMP library in dev c with gcc4.7.2

I have absolutely no idea about using gmp. Need some functions for a project and need a quick installation guide. I am Absolutely beginner to this field so please help accordingly.
I have:
Dev C++ 5.4.2 in windows 8.1 configuration with GCC4.7.2 as default
compiler.
gmp-static-mingw-4.1.tar
Please specify the correct procedure to configure gmp library.
At first put gmp.h into ..\Dev-Cpp\MinGW32\include and both libgmp.a and libgmp.la into ..\Dev-Cpp\MinGW32\lib directory, then create some project in DevCpp, for example:
#include <stdio.h>
#include <gmp.h>
int main(void)
{
mpz_t x;
mpz_init(x);
mpz_set_str(x, "12345", 10);
mpz_mul_ui(x, x, 2);
gmp_printf("%Zd\n", x);
mpz_clear(x);
return 0;
}
After that go to Project Options -> Parameters and click Add Library of Object:
From the list select libgmp.a file (your static library) and click Open:
Compile and run you project, you will see some note about Makefile update, simply confirm.
Note that GMP 4.1 is now rather old, consider latest version and/or manual compilation for best possible performance on your configuration.

MinGW completely bugged on NetBeans

The following code shoudn't produce an error:
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std ;
int main ( int argc , char** argv )
{
int n ;
cin >> n ;
cout << n ;
return 0 ;
}
Yet a get a "RUN FAILED (exit value -1,073,741,511, total time: 46ms)" whilst running MinGW/Msys on Netbeans. Any advice like switching back to Cygwin?
I recommend using MinGW Distro if you want to develop C++ under a Microsoft Windows operating system. It ships with a pretty new GCC version and with the Boost libraries.
NetBeans IDE is pretty picky regarding the build environment settings. E.g. It doesn't work together with all versions of make (we have to distinct make.exe from MSYS and mingw32-make.exe from MinGW for example) and there are problems regarding the used Java Runtime Enviroment (JRE).
With the settings shown in the following screenshot you should be able to build your example with MinGW Distro and NetBeans 8. I recommend to not configure a absolute path to the make.exe file but add that path to your Microsoft Windows environment variable PATH. Otherwise you may get build errors.
Maybe these two blog posts help if you want to use the "default" MinGW distribution:
Installing Minimum GNU for Windows (MinGW)
Configure NetBeans IDE for Minimum GNU for Windows (MinGW)
I hope this helps others as well.
Not related to your question: Don't use using namespace std:
#include <iostream>
int main(int argc, char** argv) {
int n;
std::cin >> n;
std::cout << n;
return 0;
}
I ran into this same issue (with exit code -1,073,741,511), so though a dated question, I'm posting this here for anyone else who runs into the problem.
Run the executable for the program manually. You might get an error such as "the procedure entry point __gx_personality_v0 coud not be located in the dynamic library libstdc++-6.dll". (OP has confirmed this in a comment.)
The .dll file referred to in the error message above is either not being linked, or linked incorrectly. The correct version of the .dll that needs to be linked is the one in the ...\MinGW\bin directory. In Windows, you can check the .dll file being linked by typing where libstdc++-6.dll in a command prompt; the first result that is listed will be the file that is linked. If you already see ...\MinGW\bin\libstdc++-6.dll as the first result here, my fix below will not help you.
If you see a message "INFO: Could not find files for the given pattern(s).", then ...\MinGW\bin needs to be added to your %PATH% variable. (OP has already confirmed this was not the issue.)
The issue I was having was that a program I had installed had its own (likely outdated) version of libstdc++-6.dll, which was in a folder also included in my %PATH% variable, ahead of ...\MinGW\bin. This meant that this other .dll file was being picked up and linked to during execution. This can be fixed by editing your %PATH% variable to make sure the ...\MinGW\bin entry is ahead of all other directories that also have a version of the .dll file.
Edit: The other option is to statically link the .dll at program compilation, or place a copy of the correct .dll in the program executable directory. However, neither of these fixes is 'global', and needs to be done for each project individually.
Hope this helps!

How to run a simple cpp file that requires QT?

I have QT 5.1.1 installed on my machine, but I'm having some troubles using it. I'm trying to run the following simple program that requires QT:
//Playing Video
#include "cv.h"
#include "opencv2\objdetect\objdetect.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\features2d\features2d.hpp"
#include "opencv2\calib3d\calib3d.hpp"
#include "opencv2\nonfree\nonfree.hpp"
#include "highgui.h"
#include <openbr\openbr_plugin.h>
using namespace cv;
static void printTemplate(const br::Template &t)
{
const QPoint firstEye = t.file.get<QPoint>("Affine_0");
const QPoint secondEye = t.file.get<QPoint>("Affine_1");
printf("%s eyes: (%d, %d) (%d, %d)\n", qPrintable(t.file.fileName()), firstEye.x(), firstEye.y(), secondEye.x(), secondEye.y());
}
int main(int argc, char *argv[])
{
br::Context::initialize(argc, argv);
// Retrieve classes for enrolling and comparing templates using the FaceRecognition algorithm
QSharedPointer<br::Transform> transform = br::Transform::fromAlgorithm("FaceRecognition");
QSharedPointer<br::Distance> distance = br::Distance::fromAlgorithm("FaceRecognition");
// Initialize templates
br::Template queryA("../data/MEDS/img/S354-01-t10_01.jpg");
br::Template queryB("../data/MEDS/img/S382-08-t10_01.jpg");
br::Template target("../data/MEDS/img/S354-02-t10_01.jpg");
// Enroll templates
queryA >> *transform;
queryB >> *transform;
target >> *transform;
printTemplate(queryA);
printTemplate(queryB);
printTemplate(target);
// Compare templates
float comparisonA = distance->compare(target, queryA);
float comparisonB = distance->compare(target, queryB);
// Scores range from 0 to 1 and represent match probability
printf("Genuine match score: %.3f\n", comparisonA);
printf("Impostor match score: %.3f\n", comparisonB);
br::Context::finalize();
return 0;
}
It also requires OpenCV 2.4.6.1 and OpenBR, but that's not the problem.
All the definitions (variables and functions) in the above code that are related to QT are undefined. I've tried to find the relevant h files in QT folder and to include them, but that did not succeed since I couldn't fine qtcore.h (but a different file named qtcore with lot's of includes that I don't now how to use). I've tried to add QT "include" directory under "additional include directories" in the project properties but that didn't work either. I've also tried to add QT "lib" folder under "additional library directories" but that also did not work.
Basically, I tried everything I could think of. Can someone please explain how to I use those QT definitions? I'm really stuck and I could use any help given.
Thanks,
Gil.
(Optional) Update to Qt 5.2.
Start Qt Creator.
Create a new Qt Widgets Application project. You can give the class/files random names, it doesn't matter. Uncheck the "generate form" option, as you don't need any forms.
Remove all the files other than main.cpp from the project. You do this by right-clicking on them in the project tree on the left and choosing Remove File.
Copy-paste your code into main cpp. Make sure you completely replace main.cpp's contents, the default contents shouldn't be there anymore.
Add the opencv library to the project. Right-click on the project's root, select "Add Library", and go from there.
Re-run qmake by right-clicking on the project root and selecting "Run qmake".
Build and run the project by pressing Ctrl-R (Cmd-R on mac).
Qt uses a (non-standard) custom toolchain that has to run before the Qt-dependent code can be compiled. I've never tried using Qt outside of QtCreator, but if you really need Qt I'd suggest you use the QtCreator IDE; if you're not using it already of course. It's a very decent IDE, even for non-Qt projects.
Also, if you haven't done so already, make sure the Qt SDK is installed; the headers alone are not enough. QtCreator by itself is also not enough, you'll need the SDK. If you don't feel like doing so, my suggestion would be to look at Poco. It's not a 1:1 replacement for Qt, but a very mature framework nevertheless.