I had an absolutely working project containing the Eigen 3.4.0. After installing Сuda 12.0, Visual Studio began to issue an error at the compilation stage on the script in the Eigen library itself in the project. This is happening in the file NumTraits.h in the part:
struct default_digits10_impl<T,false,false> // Floating point
{
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static int run() {
using std::log10;
using std::ceil;
typedef typename NumTraits<T>::Real Real;
return int(ceil(-log10(NumTraits<Real>::epsilon())));
}
C2665 "log10": no overloaded function can convert all types of arguments - this is error.
The library is external, I don't want to make changes in this code, I want to understand how to avoid this error.
I tried to paste
#if (defined __GNUC__) && (__GNUC__>4 || __GNUC_MINOR__>=7)
#undef _GLIBCXX_ATOMIC_BUILTINS
#undef _GLIBCXX_USE_INT128
#endif
in main file and define EIGEN_DEFAULT_DENSE_INDEX_TYPE, as it write in the description of Cuda and Eigen compatibility. But it didn't help.
Here is an addition to the question:
the error occurs when initializing a variable with the type:
using CubeXX3d = Eigen::Matrix<Eigen::Vector3d, -1, -1>;
This error occurred only because I submitted an instance of the CubeXX3d class for output:
std::cout<<instance;
(the CubeXX3d class definition is described above).
After I deleted this line, there was no error.
Related
Problem: The compiler declares a seemingly nonsensical error that a local variable in a class member function "was not declared in this scope". The code shown below is a simplified implementation of the original function, and somehow it still triggers the same error. Furthermore, the error disappears whenever I rename the variable (in each place it's used) and resumes as soon as I change the variable back to its original name ("minor"). I don't understand this behavior and can't find any information/posts on what would cause a compiler to do this. Could someone kindly offer suggestions on what might be wrong? Is it indicative of a major bug somewhere else in my code (e.g. the Matrix class definition)?
Details: I'm compiling on Linux Mint 18 using g++ on Makefiles generated by CMake. I've tried with and without a variety of compiler options (e.g. -O2, -Wall, etc.), and the result is unchanged. I've previously compiled and ran a slightly earlier version of this code/project on Windows 7 using MinGW and a self-written Makefile with no problems. I'm happy to provide additional details upon request.
Modified/minimalist code snippet from Matrix.cpp:
Matrix Matrix::BuildCofactorMatrix() const {
double minor (0.0);
minor = 1.0;
return Matrix(height_, width_);
}
Warning message:
/PATH-TO-PROJECT-ROOT/src/Matrix.cpp: In member function ‘Matrix Matrix::BuildCofactorMatrix() const’:
/PATH-TO-PROJECT-ROOT/src/Matrix.cpp:1123:5: error: ‘minor’ was not declared in this scope
minor = 1.0;
2017-08-21 Edit:
I removed unnecessary code and created a truly "Minimal, Complete, and Verifiable" example of the problem. For me, the error seems to be a function of the iostream library. If I remove the iostream inclusion, the problem seems to disappear. However, the error also depends on the c++ standard used for compiling. When I specify that g++ use, for example, -std=c++11 or -std=c++14, the problem persists, but once I remove the specification (i.e. g++ -c Matrix.cpp), the error disappears. By the way, I'm using g++ 4:5.3.1-1ubu.
Unless I'm missing something, I can't find any macros in iostream, istream, ostream, or ios that mention the term "minor", but perhaps it's further up the inclusion chain...?
Matrix.hpp:
#ifndef MATRIX_HPP
#define MATRIX_HPP
class Matrix {
public:
void BuildCofactorMatrix() const;
};
#endif
Matrix.cpp:
#include "Matrix.hpp"
#include <iostream>
void Matrix::BuildCofactorMatrix() const {
double minor (0.0);
minor = 0.0;
}
I can replicate the problem by adding #define minor(x) (x) before the function.
The macro matches minor(0.0) but not minor without the "parameter".
The line
double minor (0.0);
would be replaced by
double (0.0);
which is a valid, but useless, type cast.
So, go look for some evil macro in one of the include files.
I've done my best recently to set up boost's numeric bindings to allow me to use LAPACK from C++, but I've run into some roadblocks. First off, I have confirmed that boost is working fine, so it's something to do with my LAPACK libraries or the boost numeric bindings.
Here's a bit of code to test what I'm trying to do:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/bindings/lapack/gesvd.hpp>
#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
//#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
//#include <boost/numeric/bindings/traits/matrix_traits.hpp>
typedef boost::numeric::ublas::matrix<int> iMatrix;
typedef boost::numeric::ublas::matrix<double> dMatrix;
typedef boost::numeric::ublas::vector<int> iVector;
typedef boost::numeric::ublas::vector<double> dVector;
namespace ublas = boost::numeric::ublas;
namespace lapack = boost::numeric::bindings::lapack;
void function() {
int n = 10;
dMatrix jacobi(n,n); // then actually initialize it
dVector eigenvals(n);
dMatrix eigenvects(n);
dVector work(n);
int error = lapack::gesvd('N', 'A', jacobi, eigenvals, eigenvects, work);
std::cout << eigenvals << std::endl;
}
Now while I'm not 100% correct that this code should compile when everything is set up correctly, the errors I've been getting when building don't seem to make much sense to me.
In file included from C:\MinGW\boost\boost_1_57_0/boost/serialization/tracking.hpp:20:0,
In file included from C:\MinGW\boost\boost_1_57_0/boost/serialization/tracking.hpp:20:0,
.............
from ..\Solver.cpp:6:
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/traits/ublas_matrix.hpp: In instantiation of 'struct boost::numeric::bindings::traits::matrix_detail_traits, boost::numeric::ublas::matrix >':
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/traits/matrix_traits.hpp:48:10: required from 'struct boost::numeric::bindings::traits::matrix_traits >'
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/lapack/gesvd.hpp:167:7: required from 'int boost::numeric::bindings::lapack::gesvd(char, char, char, MatrA&, VecS&, MatrU&, MatrV&) '
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/lapack/gesvd.hpp:477:50: required from 'int boost::numeric::bindings::lapack::gesvd(char, char, MatrA&, VecS&, MatrU&, MatrV&)'
..\Solver.cpp:85:77: required from here
C:\MinGW\boost\boost_1_57_0/boost/numeric/bindings/traits/ublas_matrix.hpp:46:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE'
BOOST_STATIC_ASSERT((boost::is_same<
Again, I have tested that boost and ublas by itself is working fine. When I comment out the lapack::gesvd line of code, everything compiles and runs fine. As far as I can tell, these errors means that I have correctly linked LAPACK to the program (there are no unresolved symbols), and my program is able to find the correct binding files (calling lapack::gesvd returns a different error when you give it incorrect input). So I'm at a loss.
I'm on Windows 64 bit, using Eclipse, C++, boost, ublas, and LAPACK. Information about the boost numeric bindings to LAPACK can be found here: http://git.tiker.net/boost-numeric-bindings.git/blob_plain/be4a548307f3e95786acb3487e571bdffe738e4a:/libs/numeric/bindings/lapack/doc/index.html
Any advice about the overall linking/compiling process using boost numeric bindings+LAPACK would be appreciated. I honestly haven't been able to find any good examples online.
So I figured out my problem(s) -- there were several,-- and I thought I should answer my own question so that others might benefit.
First off, my LAPACK installation was incorrect. I had downloaded the 64-bit version instead of the 32-bit version. Even though it's 2015, somehow I'm stuck using a 32-bit version of the lapack dll...
Secondly, linking in Eclipse works a little differently than I thought. Going to the project properties, C/C++ Build -> Settings -> Tool Settings -> MinGW C++ Linker -> Libraries allows you to link libraries. Under the top libraries option (-l), I added lapack and blas. Under the bottom Library search path (-L), I added the location of the .dll files.
At this point, I could run sample LAPACK code, just not use the boost numeric bindings. Thirdly, I figured out what the numeric bindings traits includes were. From the traits overview page, I was able to figure out that in order to use particular vector or matrix class in bindings to LAPACK, I had to include proper traits specialization. For instance, using the boost::numeric::ublas::matrix object and sending it to LAPACK required including the trait header file <boost/numeric/bindings/traits/ublas_matrix.hpp>.
This solved my error that you see from the original post, and I could use the boost numeric bindings. Finally, I had messed up my example code because I didn't actually understand what gesvd was doing. It was just a test program, so it's no big deal, but I'll attach the working code below to show the singular value decomposition that I had initially attempted.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/bindings/lapack/gesvd.hpp>
#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
#include <boost/numeric/bindings/traits/ublas_vector.hpp>
#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
typedef boost::numeric::ublas::matrix<int> iMatrix;
typedef boost::numeric::ublas::matrix<double> dMatrix;
typedef boost::numeric::ublas::vector<int> iVector;
typedef boost::numeric::ublas::vector<double> dVector;
namespace ublas = boost::numeric::ublas;
namespace lapack = boost::numeric::bindings::lapack;
void function() {
int n = 10;
dMatrix jacobi(n,n); // then actually initialize it
dVector eigenvals(n);
//int error = lapack::gesvd('S','S', jacobi, eigenvals, eigenvects1, eigenvects2);
int error = lapack::syevd('V','L', jacobi, eigenvals, lapack::optimal_workspace() );
std::cout << eigenvals << std::endl;
std::cout << jacobi << std::endl;
}
Briefly, I try to init a matrix as follows:
struct MyClass {
arma::mat _mymat;
};
MyClass::MyClass() :
_mymat(0,0)
{
}
but in the VS2010 debugger, the properties are
{n_rows=0 n_cols=14829735428352901220 n_elem=7925840 ... }
Later I try to set the dimensions again to 3x3, but then the properties change to
{n_rows=3435973836 n_cols=3435973836 n_elem=3435973836 ... }
and when I use MyClass._mymat in multiplication the program throws an exception at runtime complaining that the matrix dimensions are not equal.
The platform is VS2010, 64-bit with armadillo 4.200
I have also tried this with previous versions of Armadillo to the same effect.
This error does not occur under Win32 32-bit.
I found the answer.
TL;DR: ARMA_64BIT_WORD was not defined for the source file I was using, but it was defined for other object files, thus creating an unstable mix of 32-bit and 64-bit word sizes in the Armadillo library.
The simple fix was to add ARMA_64BIT_WORD as a preprocessor macro in the configuration properties for the project.
I'm trying to use the date/time facilities of the C++ Boost library v1.41. (Note: this is Linux, not Windows; g++ v4.4.7)
Code:
#include <boost/date_time/posix_time/posix_time.hpp>
using boost::posix_time::ptime;
using boost::date_time::microsec_clock;
:
t1 = (boost::date_time::microsec_clock::local_time()); // line 208
The error:
tom.cpp:208: error: 'template<class time_type> class boost::date_time::microsec_clock' used without template parameters
Now, there's this in boost/date_time/posix_time/posix_time_types.hpp:
#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
//! A time clock that has a resolution of one microsecond
/*! \ingroup time_basics
*/
typedef date_time::microsec_clock<ptime> microsec_clock;
#endif
What I'm concluding is that BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK is undefined, resulting in the typedef never happening, resulting in the reference to "microsec_clock" looking like it needed a template parameter.
As far as I can tell, I'm following the Boost date_time documentation to the letter. Any ideas?
I have the same problem right now.
Yesterday it worked without any problems but today I needed to delete all my compiled libraries and recompile them due to a svn corruption problem. Ever since this error occurred.
The way to fix it is rather simple.
Just use
t1 = (boost::posix_time::microsec_clock::local_time());
instead of
t1 = (boost::date_time::microsec_clock::local_time());
This will preset the time type to posix format however it will not fix the initial problem with BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK.
I hope this was of help to you.
I've inherited a C++ project that compiled fine in VS2005, but when I open it in VS2010 I get lots of IntelliSense erros like this:
IntelliSense: expression must have integral or enum type
Actually opening one of the cpp files in the project seems to cause the errors to appear.
Here's an example of the type of line that causes the error.
if (pInfoset->Fields->Item["Contact"]->Size <= 0)
I recognize the code, that's ADO syntax. You are battling a non-standard language extension that made COM programming easier in the previous decade. It allowed declaring properties on a C++ class, using the __declspec(property) declarator. An example:
class Example {
public:
int GetX(const char* indexer) { return 42;}
void PutX(const char* indexer, int value) {}
__declspec(property(get=GetX,put=PutX)) int x[];
};
int main()
{
Example e;
int value = e.x["foo"]; // Barf
return 0;
}
The IntelliSense parser was completely overhauled in VS2010 and re-implemented by using the Edison Design Group front-end. It just isn't compatible enough with the language extension and trips over the index operator usage. For which they can be forgiven, I'd say.
You can complain about this at connect.microsoft.com but I wouldn't expect miracles. The problem is still present in VS2012. A workaround is to stop using the virtual property and use the getter function instead, get_Item("Contact") in your case.
From something you said in the comments (about IntelliSense not finding a .tli file), the errors should go away once you build the solution. .tli (and .tlh) files are automatically-generated files that are created by the #import directive, but obviously you need to compile the files that have #import directives in order for those files to be generated (IntelliSense alone won't generate them).