I created visual studio files for the c++ library g2o using cmake. But when I try to build it, it is failing showing an error at some template definitions.
template<>
inline void axpy(const Eigen::MatrixXd& A, const Eigen::Map<const Eigen::VectorXd>& x, int xoff, Eigen::Map<Eigen::VectorXd>& y, int yoff)
{
y.segment(yoff, A.rows()) += A * x.segment(xoff, A.cols());
}
As I am not an expert in c++, I am not sure what is going wrong in this line of code. I tried commenting this code and building. Then the build fails on the next template definition. Is it an issue with visual studio?
The error shown is
The same code is working perfectly on linux. But I need to run it on my windows machine as debugging is easier and I have only limited access to the linux machine. Any help will be appreciated.
In windows VS environment, you need to change the template specification.
Change the template<> into template< Eigen::MatrixXd > will works
Related
The problem with Visual Studio and warnings when the variables are uninitialized
I have tried another compiler like Clang. The Clang was able to generate warnings.
//clang 3.8.0
//MSVS 2017
#include<iostream>
using namespace std;
class dummy
{
public:
void dummyFunction()
{
static_cast<int>(m_DummyVariable);
}
private:
double m_DummyVariable;
};
int main()
{
dummy obj;
double outside;
static_cast<int>(outside);
obj.dummyFunction();
return 0;
}
I expected to get three warnings as the online clang was able to do so. However, in Visual Studio regardless of the warning level(1,2,3,4 or all warnings options) which I have set in project's properties, I have not been able to get any warnings. Do I have to change any property of my project?
If you right click on you project and hit properties, go to the bottom and click on Code Analysis. Changing rule set to Microsoft All Rules as well as ticking the box to run code analysis on build makes warnings appear for me.
Worth noting that as soon as I send the outside variable to standard output Visual Studio throws a warning and an error.
I am using Visual Studio 2015 Update 3.
I get a fatal error:
(code C1001) : An internal error has occurred in the compiler.
Here is the code :
template<typename T>
constexpr T epsilon = std::numeric_limits<T>::epsilon();
I read it was fixed in Visual Studio Update 2. Can someone explain me why I am getting this error? Thanks in advance.
Any internal error (ICE) is a compiler bug. You get it because you have happened to trigger that bug. For this compiler you can report it at Microsoft Connect.
For such a report you need an example with an expected correct result, and the erroneous result.
The following test program compiles & runs nicely with MinGW g++ 5.1
#include <limits>
template<typename T>
constexpr T epsilon = std::numeric_limits<T>::epsilon();
#include <iostream>
using namespace std;
auto main() -> int
{
cout << epsilon<double> << endl;
}
Output:
2.22045e-016
With Visual C++ 2015 update 2 it produces an ICE:
foo.cpp(10): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\symbols.c', line 28114)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
foo.cpp(10): note: see reference to variable template 'const double epsilon' being compiled
Compiler version:
> cl /nologo- 2>&1 | find "++"
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23725 for x86
I've raised this as a bug with Microsoft, but they have had a fix since early 2017 which has not been released from what I can see as of today.
I've also provided a project on GitLab and given information to Microsoft for this project here: https://gitlab.com/cppocl/tostring
Loading the .sln and compiling currently crashes with Visual Studio 2015 update 2 or 3, and Visual Studio Enterprise 2017 version 15.3.1.
It does seem that the combination of template and constexpr causes the compiler to crash.
I've seen reports for Visual Studio 2017 describing similar types of problems.
This link says fixed pending release:
https://developercommunity.visualstudio.com/content/problem/18155/msvc-2017-c-fatal-error-c1001-constexpr-initializa.html
Visual Studio 2015 backlog of bugs relating to constexpr is here:
https://blogs.msdn.microsoft.com/vcblog/2015/12/02/constexpr-in-vs2015-update-1/
EDIT:
I also don't believe changing optimization settings will make any difference, as has been recommended in other posts.
I have experimented with these settings and applied recommended patches without success so far.
I am porting large project from Linux to WinCE. Currently facing problem of linking error LNK2019.
AS I can see from the error it is because of the overloaded static function is not defined, only declaration. E.g:
template<bool taValue>
struct type
{
};
typedef type<true> MTrue;
typedef type<false> MFalse;
static int getData(int i, MTrue) { return 2; }
static int getData(int i, MFalse);
This is just a sample of code and not exact scenario.
The compilation is working well for Linux but it is falling linking time for WinCE. If I comment out the overloaded undefined function in Linux, then I can see same set of linking error in Linux as well.
I am not sure, why this is happening this case?
Is there any compiler option which can avoid this linking error in case of Linux?
Note: compiler gcc/g++ 4.2.2 and cmake version 3.2.2
I installed Visual C++ Compiler November 2012 CTP and created a C++ console project. I wrote this in
template<typename T>
void Test(T value){
}
template<typename T, typename... Args>
void Test(T value, Args... args){
Test(value);
Test(args...);
}
int main(){
Test(1,2,3);
}
Then I pressed F6 to build in the IDE. I got this error on line 4
error C2143: syntax error : missing ',' before '...'
The compile list "variadic templates" so I believe this should work. I do understand intellisense may be incorrect however the 'compiler' should work. Can I not build from the IDE? Do I have to enable something somewhere? int i{4}; doesn't seem to work either and I am sure thats valid uniform initialization.
In the Project Properties, make sure to select the Microsoft Visual C++ Compiler Nov 2012 CTP:
The new toolchain does not replace the existing Visual C++ 2012 toolchain, and it is not enabled by default. It's installed side-by-side with the existing toolchain.
If you select the new toolchain, your program will compiler without error.
I am getting run time crash in the following piece of code and not able to debug also. Please review and let me know what's going on.
// CppConsole.cpp : Defines the entry point for the console application.
//#include "stdafx.h"#include <iostream>#include <assert.h>
class Test : public std::tr1::enable_shared_from_this<Test>
{
public:
Test():x(0),y(0),z(0){};
int x;
float y;
double z;
};
int _tmain(int argc, _TCHAR* argv[])
{
std::tr1::shared_ptr<Test> t1(new Test);
std::tr1::shared_ptr<Test> t2 = t1->shared_from_this();
return 0;
}
I have include all the headers and the program is compiling fine. This is the error i am getting:
CppConsole.exe - Entry Point Not Found The procedure entry point
?_Xweak#tr1#std##YAXXZ could not be located in the dynamic link
library MSVCP90D.dll
If I comment out this line
std::tr1::shared_ptr t2 = t1->shared_from_this();
the program runs without crashing.
Update: Question can be closed for now. I will try to install VS feature pack and see weather the program executes without any crashes.
Googled it (The procedure entry point ?_Xweak),found this : http://blog.nilretain.org/
EDIT : I Build and Run it successfully on my msvc 2008 on xp-sp3 ,which has later version of msvcp90d.dll.
Maybe you can download and install the latest redist-version of msvc90 and rebuild.
EDIT: your dependencies says something is missing. check this out :
http://answers.yahoo.com/question/index?qid=20090623140325AAInugo
You need a template argument:
std::tr1::shared_ptr<Test> t1(new Test);
std::tr1::shared_ptr<Test> t2 = t1->shared_from_this();
The compiler should report an error if it is not present. (Visual C++ 2010 does)
It appears that your compiler is not linking against a DLL with the needed runtime functions. For instance, if you added the headers to your include path, but don't link to the latest version of the C++ runtime (check your project's settings), or installing the Visual C++ 2008 feature pack didn't work, or you installed the feature pack but then tried to compile from Visual Studio 2005, etc.
Basically the "process the source code (including headers)" step is working fine, but the "link all the DLLs" step is failing. And it's failing because the runtime you're linking against doesn't have the needed functions for shared_ptrs or weak_ptrs.
I had this problem when developing under M$ Windows SP3 with M$ Visual Studio 2008. I tried and combined many hints that I could find on the web. To no avail. The solution was simple, I had to install SP1 pack for M$ Visual Studio 2008!
The thing is that my external DLLs used C++ TR1 functions that I was not aware of. The M$ Visual Studio 2008 without SP does not have the right runtime DLLs.
So, just make sure you have that SP1 for your M$ Visual Studio 2008 first before trying any other solution.