What's the header file of gluLookAt in Qt? - qt

I got some code for using OpenGL in Qt. And when I run it I got error as below:
C:\Users\Administrator\Desktop\NeHe6\NeHe6-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\..\NeHe6\nehewidget.cpp:54: error: 'gluLookAt' was not declared in this scope
It seems the header is missing. And the current headers are:
#include "nehewidget.h"
#include <QtGui>
#include <qtopengl\QtOpenGL>
And "nehewidget.h" contains below headers:
#include <qtopengl\QGLWidget>
#include <QTimer>
Could anyone tell me what is the missing header?

It looks like it cant find the libraries you need. Check your installation of the openGL helper libraries. Specifically it is looking for GLU. You need to add it to your linker options, for example -lGLU. You then need to include it your code:
#include <GL/glu.h>
Examples of linking and including GLU (and GLUT) across multiple platforms can be found here

Add this line at the end of the .pro file and you add the lib to your project:
LIBS += -L/usr/local/lib -lGLU

Related

Roxygen2 adds `import(RcppArmadillo)` to my `NAMESPACE`

Can I stop it?
That requires to add RcppArmadillo to Imports, when otherwise LinkingTo would be enough.
Does this already trigger Roxygen to do this?
#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]

C++17 in a package with Rcpp

#include <cmath>
#include <math.h>
#include <Rcpp.h>
// [[Rcpp::plugins("cpp17")]]
// [[Rcpp::export]]
double rcpp_hello_world(Rcpp::NumericVector x) {
double z;
z = std::cyl_bessel_i(0, x[0]);
return z ;
}
When I run the above code and call it using sourceCpp, it works as expected. However inside a R package setup I get
error: cyl_bessel_iis not a member of ‘std
11 | z = std::cyl_bessel_i[0]);
| ^~~~~~~~~~~~
make: *** [/usr/lib64/R/etc/Makeconf:177: rcpp_hello_world.o] Error 1
ERROR: compilation failed for package ‘Package’
upon running Rcpp::compileAttributes() and devtools::document(). I initialised the package with Rcpp.package.skeleton.
cyl_bessel_i was added to the standard library in C++17.
I am using gcc-12.1.0-2 and R-4.2.0-3. I am on Arch Linux.
The default C++ standard used in current versions of R is C++11 (or C++14 if available). Since you require C++17, you need to declare it in the src/Makevars file, using the line
CXX_STD=CXX17
In a comment you referred to the Rcpp documentation which says that Makevars is optional since Rcpp 0.11.0. I think that was written about linking to the Rcpp libs, but it is also true here, as pointed out by #MikkoMarttila: you can alternatively declare the C++ version in the SystemRequirements: field of the DESCRIPTION file, e.g.
SystemRequirements: C++17

Qt with OpenCV: The program has unexpectedly finished

I just installed Qt 5.15 and is testing how it works with opencv. I downloaded prebuild Opencv4.3, and set up a .pri file for being deployed in Qt.
The include and libs are as follows in the .pri file:
INCLUDEPATH += C:/opencv/opencv-4.3.0-prebuild/include
CONFIG(release, debug|release):{
LIBS += -LC:/opencv/opencv-4.3.0-prebuild/x64/vc14/lib \
-lopencv_world430
}
CONFIG(debug, debug|release):{
LIBS += -LC:/opencv/opencv-4.3.0-prebuild/x64/vc14/lib \
-lopencv_world430d
}
Then I run a simple image display domo:
#include "opencv2/opencv.hpp"
using namespace cv;
Mat img = imread("image.png");
if(img.empty())
{
qDebug()<<"Could not find the image";
}
else
{
namedWindow("Image");
imshow("Image", img);
}
The resulting error message: The program has unexpectedly finished. The process was ended forcefully.
Without linking with OpenCV, Qt itself works just fine.
What causes the problem?
It's not clear where is your example code is located. Is it in main?
Generally in OpenCV you also have an event loop (as in Qt) but it is hidden.
So if you want to actually see the namedWindow, you need to call cv::waitKey().
You can call it like cv::waitKey(1) if you do it periodically.
But generally you should do only the image processing in OpenCV, convert the cv::Mat to QImage, and show that in Qt.
I found this issue is due to an improper debugger set in the Qt Creator. Refer to the posts QtCreator no debugger set up (Windows). and Cannot run Qt example in Qt creator: The program has unexpectedly finished, and the official document https://doc.qt.io/qtcreator/creator-debugger-engines.html#supported-native-debugger-versions and https://doc.qt.io/qtcreator/creator-debugger-engines.html#debugging-tools-for-windows
For the crash,
My first guess is your environment variable is not set properly. Please check you assign the env. variables properly.
Writing imshow() in Qt won't work. As suggested by tr3w, you should convert to a qimage.
Mat img;
QImage img1 = QImage((uchar *) img.data,img.cols,img.rows,img.step,QImage::Format_Indexed8);
You can replace with your supported image format instead of indexed8.
I solved the problem as follows: I have added the paths to opencv's bin and lib files to PATH.

Why do we both "include" and "depends" on RcppArmadillo?

To use RcppArmadillo, we're often instructed to have the following lines at the top:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
Why do we need both? Isn't the #include directive sufficient for us to have access to all functions defined inside the scope of RcppArmadillo?
There are two different things at play:
The compiler needs the header RcppArmadillo.h in order to know about types from (Rcpp)Armadillo, Rcpp (as this one pulls in Rcpp.h as well) and therefore R. I presume you know you need this. But ...
How would R know to add the -I... flag required for this? It wouldn't!
At a package level the LinkingTo: helps for the header case. But in deeper sense sometimes we need headers and linking (ie RcppGSL) and in that case, the hook we have here via Rcpp::depends into Rcpp Attributes ensures we can do this.
So the // [[Rcpp::depends(RcppArmadillo)]] helps for sourceCpp() use. It is not needed in a package. "Plugins" like this are discussed a little in the Rcpp Attributes vignette.

C++ R package error: uploading library

I submitted my package to the CRAN repository. The package was accepted without errors but in the second step of checking the CRAN maintainers reported the following error.
Unfortunately I don't understand how I can fix it.
In file included from /Builds/CRAN-QA-Simon/packages/mavericks-x86_64/Rlib/3.3/RcppArmadillo/include/armadillo:23:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/fstream:864:20: error:
no member named 'Rf_error' in 'std::__1::codecvt_base'; did you mean simply 'Rf_error'?
if (__r == codecvt_base::error)
^~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Resources/include/R_ext/Error.h:35:12: note:
'Rf_error' declared here
void NORET Rf_error(const char *, ...);
^
In my C++ file, I wrote:
#include <math.h>
#include "ANN/ANN.h"
#include "NN.h"
#include <R.h>
#include "RcppArmadillo.h"
#include <map>
#include <vector>
#include <iostream>
How do I have to correct this? Has Rpp.h to be included?
R itself is written in C, due to its early start way back in the early 1990s. C has no namespaces -- which can lead to conflicts as we lack the namespace separation. Identifiers from different libraries sharing the same name can be mistaken. This has happened here.
R uses, in its C API, functions length(), error(), .... etc which, given how common the name is, are likely to clash. So R has as mechanism of prepending Rf_ to its symbols: error becomes Rf_error. This use the preprecessor, which is reasonably dumb (as opposed to using the compiler itself). So when R sees error it wants it to be Rf_error.
What happens here is that you very likely has #include <RcppArmadillo.h> (and therefore the implicit #include <Rcpp.h> before the include for your actual library. Try it the other way around. That way R's messing with its error() will not interfere with the library one which is confusing you here.

Resources