It's been years since I used C++ and so I'm very rusty. I'm trying to test out the Geos library, but I'm unable to get a simple Hello World example to compile
https://libgeos.org/usage/download/
This is what I tried:
I downloaded and extracted the files
Created a new C++ project in Visual Studio
Added the headers folder into the Visual Studio Include Directories for the project.
Then I tried to use the library in my main.cpp:
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <iostream>
#include <memory>
geos::geom::Polygon * MakeBox(double xmin, double ymin, double xmax, double ymax) {
std::unique_ptr<geos::geom::PrecisionModel> pm(new geos::geom::PrecisionModel());
geos::geom::GeometryFactory::unique_ptr factory = geos::geom::GeometryFactory::create(pm.get(), -1);
geos::geom::CoordinateSequence* temp = factory->getCoordinateSequenceFactory()->create((std::size_t)0, 0);
temp->add(geos::geom::Coordinate(xmin, ymin));
temp->add(geos::geom::Coordinate(xmin, ymax));
temp->add(geos::geom::Coordinate(xmax, ymax));
temp->add(geos::geom::Coordinate(xmax, ymin));
//Must close the linear ring or we will get an error:
//"Points of LinearRing do not form a closed linestring"
temp->add(geos::geom::Coordinate(xmin, ymin));
geos::geom::LinearRing* shell = factory->createLinearRing(temp);
//NULL in this case could instead be a collection of one or more holes
//in the interior of the polygon
return factory->createPolygon(shell, NULL);
}
int main() {
geos::geom::Polygon* box = MakeBox(0, 0, 10, 10);
std::cout << box->getArea() << std::endl;
delete box; //Important to avoid memory leaks
}
I'm getting multiple errors, but they all seem to indicate that the library is not loaded correctly
Severity Code Description Project File Line Suppression State Error
(active) E0135 class "geos::geom::GeometryFactory" has no member
"unique_ptr" TestGeos C:\TestGeos\TestGeos.cpp 15
What am I missing in order to use the library?
Related
I am trying to use the GraphicsPath::AddString() method of GDI+ in my libcinder project.
The idea is to create a path of a letter/glyph via the mentioned method and later pass that to gl::draw() and box2d's b2FixtureDef. The goal is create falling letters that show an exact collision behaviour.
However the following example taken from learn.microsoft.com throws several errors at me.
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
#include <Box2D/Box2D.h>
#include <gdiplus.h>
#pragma comment (lib, "gdiplus.lib")
using namespace Gdiplus;
using namespace ci;
using namespace ci::app;
using namespace std;
// ...
void MyApp::draw()
{
FontFamily fontFamily(L"Times New Roman");
GraphicsPath path;
// const WCHAR
// Status AddString(
// IN const WCHAR *string,
// IN INT length,
// IN const FontFamily *family,
// IN INT style,
// IN REAL emSize, // World units
// IN const PointF &origin,
// IN const StringFormat *format
//)
path.AddString(
L"Hello World",
-1, // NULL-terminated string
&FontFamily("Arial"),
FontStyleRegular,
48,
PointF(50.0f, 50.0f),
NULL);
}
There are several issues with my code that just cant get fixed... My project's target platform version is 8.1 and the platform toolset is Visual Studio 2015 (v140). The headers are there and can be browsed to when hitting F12.
FontFamily fontFamily(L"Times New Roman");
"Cannot initialize local variable 'fontFamily' of type 'FontFamily'
with lvalue of type 'wchar_t const[16]'
GraphicsPath path;
"No default constructor exists for class "GraphicsPath""
path.AddString(...)
"class 'GraphicsPath' has no member 'AddString'"
Any help is very appreciated. I have spent hours with this issues with zero progress.
After searching high and low I figured it out. I was missing a couple of includes. But to be honest, I still don't really understand, why the compiler complained with that specific message...
The following does compile for me and produces the path coordinates for the letter "A".
// other includes
#include <windows.h>
#include <ObjIdl.h>
#include <minmax.h>
#include <gdiplus.h>
using namespace Gdiplus;
using namespace ci;
using namespace ci::app;
#pragma comment (lib, "Gdiplus.lib")
// ...
void MyApp::setup()
{
// ...
GraphicsPath p(FillModeAlternate);
FontFamily fontFamily(L"Arial");
if (p.AddString(L"A", -1, &fontFamily, FontStyleRegular, 48, PointF(0.0f, 0.0f), NULL) != Status::Ok)
{
std::cout << "Error while adding points" << std::endl;
}
PointF points[64];
if (p.GetPathPoints(points, sizeof(points)) != Status::Ok)
{
std::cout << "Error while getting points" << std::endl;
}
}
I am making a game that can be played on mac and windows with cocos2d-x.
I first wrote the code in mac's Xcode, and it worked on mac.
When I took the project to windows and tried to build it in Visual Studio 2017, an error occurred.
Error C1083 Cannot open include file: 'cxxabi.h': No such file or directory Narazumono c:\users\masanori\desktop\narazumono3.17\classes_win\nrzcoding.cpp 10
I use cxxabi.h to get the class name of the object.
#include "NRZCoding.h"
#include <cxxabi.h>
#include <cstdio>
#include <algorithm>
#include "NRZUtils.h"
using namespace std;
USING_NS_CC;
namespace NRZCoding {
...
const string& EncodableObject::getClassName()
{
if (_className.size() > 0) {
return _className;
}
const type_info& id = typeid(*this);
int stat;
char *name = abi::__cxa_demangle(id.name(),0,0,&stat);
CCASSERT(name != NULL && stat == 0, "failed to demangle");
_className = string(name);
free(name);
return _className;
}
...
What do I need to do?
I am using cocos2d-x 3.17.1 and Visual Studio 2017.
Thank you.
I am very new to Visual Studio, C++ and the Oculus SDK, but have experience with Fortran, Matlab, and coding in general.
I have got the basic C++ libraries working, so #include iostream works.
I have got the LibOVR directory included, so that #include OVR_CAPI.h works.
I opened the LibOVR project into VS2015 and rebuilt it, which worked, creating a new LibOVR.lib file.
I moved the new .lib file into my project folder and also added this file path to the Linker -> Input.
But when I try to compile my own code, the basic ovr_initialize() command is said to be undefined.
I am just trying to get a basic code setup to extract the head position data from the IMU in the Oculus Rift, and eventually hoping to integrate this with some matlab code.
Here is my starting code, mostly commented out for now:
#include <iostream>
// Include the OculusVR SDK
#include <OVR_CAPI.h>
using namespace std;
int main()
{
int MyNumb;
cout << "Please, enter an integer: ";
cin >> MyNumb;
cin.ignore();
cout << "You entered: " << MyNumb;
cin.get();
return 1;
}
void application()
{
ovrresult result = ovr_initialize(nullptr); *THIS LINE GIVES ERROR*
// if (ovr_failure(result))
// return;
//
// ovrsession session;
// ovrgraphicsluid luid;
// result = ovr_create(&session, &luid);
// if (ovr_failure(result))
// {
// ovr_shutdown();
// return;
// }
//
// ovrhmddesc desc = ovr_gethmddesc(session);
// ovrsizei resolution = desc.resolution;
//
// ovr_destroy(session);
// ovr_shutdown();
}
Any help getting this up and running would be greatly appreciated!!
I'm trying to start using allegro5 with C++. I copied the first code from a tutorial just to see if it'll work and here it is:
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
int main()
{
al_init();
al_install_keyboard();
al_init_image_addon();
ALLEGRO_KEYBOARD_STATE klawiatura;
ALLEGRO_DISPLAY *okno = al_create_display(320, 240);
al_set_window_title(okno, "Allegro5 kurs pierwsze okno");
ALLEGRO_BITMAP *obrazek = al_load_bitmap("widok.png");
while (!al_key_down(&klawiatura, ALLEGRO_KEY_ESCAPE))
{
al_get_keyboard_state(&klawiatura);
al_clear_to_color(al_map_rgb(0, 255, 0));
al_draw_bitmap(obrazek, 0, 0, 0);
al_flip_display();
}
al_destroy_display(okno);
al_destroy_bitmap(obrazek);
al_rest(5.0);
return 0;
}
I keep getting the error
C861 identifier "al_init_image_addon" is undefined
Is there some kind of a new version of this command?
al_init_image_addon is defined in allegro_image.h. Add the following:
#include <allegro5/allegro_image.h>
So, you didn't make it as a final answer.
Check if you imported the allegro image header.
#include <allegro5/allegro_image.h>
In case you have Allegro with Visual Studio, you have to check the option Image addon in the next path: Project properties -> Allegro 5 -> Image Addon. Is a checkbox.
I am trying to use graph library using opencv.
This is the code that I have written , and am building this on Visual studio 2010.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "GraphUtils.h"
using namespace cv;
using namespace std;
int main()
{
float floatArray[4]= {1,1,2,2};
showFloatGraph("Rotation Angle", floatArray, 4 );
return 0;
}
There is no compilation error.
However, I am getting following linking error:
Error 1 error LNK2019: unresolved external symbol _showFloatGraph
referenced in function _main C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\opencv1\helloworld.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\Debug\opencv1.exe
I have put the two files (GraphUtils.h and GraphUtils.c) with my .cpp file.
Why I am getting these compilation errors whenever I am using third party libraries (.c and .h) files, since I get this linking error also when using other library. I asked the question here
In Properties=>Linker=>input=>Additional dependencies , I have added :
opencv_core231d.lib;opencv_highgui231d.lib;opencv_imgproc231d.lib;opencv_features2d231d.lib;opencv_calib3d231d.lib;%(AdditionalDependencies)
And in fact my basic opencv program for image display works fine.
Do I need to do something special when using these libraries. As of now I just copy paste the .c and .h files in the folder where my .cpp file is present. Do I need to do something more ?
Update:
I found that the the file GraphUtils.c has the following code:
// OpenCV
#include <cv.h>
#include <cxcore.h>
#ifdef USE_HIGHGUI
#include <highgui.h>
#endif
I found that the cv.h, cxcore.h and highgui.h are actually present in opencv 2.3.1/opencv folder and so I changed it like this:
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#ifdef USE_HIGHGUI
#include <opencv/highgui.h>
#endif
Unfortunately this gave rise to more linking errors.
Update
The following program works fine.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include<conio.h>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
Mat img = imread("xyz.bmp", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
getch();
return 0;
}
But this program always gives error; no header file recognized. so no function would work:
#include "cv.h" //main OpenCV header
#include "highgui.h" //GUI header
int main() {
// declare a new IplImage pointer
IplImage* myimage;
// load an image
myimage = cvLoadImage("sayyidsmile.jpg",1); //change the file name with your own image
//create a new window & display the image
cvNamedWindow("Smile", 1);
cvMoveWindow("Smile", 100, 100);
cvShowImage("Smile", myimage);
//wait for key to close the window
cvWaitKey(0);
cvDestroyWindow( "Smile" );
cvReleaseImage( &myimage );
return 0;
}
Details on Env. Variables
I followed this article to set EVs.
Currently my variables are like this:
Name Value
OpenCV: C:\Users\Yuvue\Desktop\OpenCV2.3.1
INCLUDE: %OPENCV%\build\include
LIB: %OPENCV%\build\x86\vc10\lib
Path: %OPENCV%\build\x86\vc10\bin
Under Properties => VC++ Directories=> Library Directories, I have added the following:
$(OPENCV)\build\x86\vc10\lib
The second program compiles when I explicitly gives path of cv.h in the include. But if I do so with any of the third party libraries when they have used #include, it starts giving linking error (my original question).
Please help me sort this!!