GDAL Library Header Files Error and Warningsin With Visual Studio 2019 - c++

I am using GDAL in visual studio 2019 community version,and I used the sample code in the their official site which is down below,the program compiles, runs and outputs fine, but I got a list of errors and warnings, I don't know if I should ignore them or make some change on header files, anyone encounter issues like this before? hope someone could give me some advice, thank you.
sample code:
/*gdal_test*/
#include <iostream>
#include <gdal_priv.h>
#include <cpl_conv.h>
using namespace std;
int main()
{
const char* pszFile;
GDALAllRegister();
pszFile = "E:/190807/mosaic_data/S2_1_170215.tif";
GDALDataset* poDataset = (GDALDataset*)GDALOpen(pszFile, GA_ReadOnly);
GDALRasterBand* poBand = poDataset->GetRasterBand(1);
int xsize = poBand->GetXSize();
int ysize = poBand->GetYSize();
cout << xsize << endl;
cout << ysize << endl;
system("pause");
return 0;
}
error list mainly contains these three main issue:
Error (active) E0065 expected a ';' gdaltest C:\MSVC_Library\GDAL\warmerda\bld\include C:\MSVC_Library\GDAL\warmerda\bld\include\ogr_geometry.h 387
Error (active) E1455 member function declared with 'override' does not override a base class member gdaltest C:\MSVC_Library\GDAL\warmerda\bld\include C:\MSVC_Library\GDAL\warmerda\bld\include\ogr_geometry.h 1139
Warning C26812 The enum type 'CPLErr' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). gdaltest C:\MSVC_Library\GDAL\warmerda\bld\include C:\MSVC_Library\GDAL\warmerda\bld\include\cpl_error.h 244
should I change the syntax in header files? will change it effect something? Or should I just ignore these errors?

You state that your program, "compiles, runs and outputs fine," so, the errors you are seeing are being reported by the "Intellisense" tool in Visual Studio.
To stop displaying these, go to the "Error List" window and select the "Build Only" option:
The C26812 warning message can be disabled as described in my answer to your recent question.

Related

How to detect USRP usb type?

When i include uhd/usb_control.hpp in my main.cpp :
#include <uhd/transport/usb_control.hpp>
/* Some other includes */
int main (void)
{
uhd::transport::usb_control::sptr usbSpeed;
usbSpeed = uhd::transport::usb_control::make(handle, 0);
/* `handle` is a `usb_device_handle::vid_pid_pair_t` */
}
I got error from here:
static sptr make(usb_device_handle::sptr handle, const int interface);
Error:
unexpected token struct. Did you forget a ';'
struct: missing tag name
And another strange error in:
usbSpeed = uhd::transport::usb_control::make(handle, 0);
Error:
Cannot convert argument 2 from int to const int
The only implementation that i find for uhd::transport::usb_control::make is uhd/transport/usb_dummy_impl.cpp which only throw an exception.
Environment information:
Compiler: MS Visual Studio 2017
OS: MS Windows 10
C++ Standard: 17
How to fix those errors ? I only what to detect the USRP usb type. For this i read the uhd source code and i find the uhd/transport/usb_control.hpp, But I have encountered those errors.
maybe the cause of this unexpected behavior is related to your included files and a conflict between some of them, as you mentioned in addition of #include <uhd/transport/usb_control.hpp> you have some other includes. i suggest move this include line upper and lower of other includes and test your code again.
wish my suggest be useful.

Visual Studio 2013 Unnecessary Syntax Errors

EDIT: Thanks to some help, I see that I was just missing parentheses. Problem solved.
Recently Visual Studio has been giving me errors on the simplest things that are not actually wrong, and because of this I cannot run any program, and it is very frustrating. I have Visual Studio Professional 2013 with Update 5, running on Windows 10. Let me give an example.
When I write the program:
#include <iostream>
using namespace std;
int main
{
cout << "Hello World!" << endl;
return 0;
}
I get the errors:
main.cpp(6): error C2143: syntax error : missing '}' before ';'
main.cpp(8): error C2059: syntax error : 'return'
main.cpp(9): error C2059: syntax error : '}'
main.cpp(9): error C2143: syntax error : missing ';' before '}'
Also, on cout, IntelliSense gives me the error "no suitable conversion function from 'std::basic_ostream...' to 'int' exists". And on return it says "error: expected a declaration." That same error is also given on the final bracket.
Why am I getting all of these nonsense errors and how to I make them stop appearing so I can run a program?
(P.S. I have tried writing the program with and without "using namespace std" and nothing changes.)
You're missing parenetheses from main:
#include <iostream>
using namespace std;
int main()
^^
{
cout << "Hello World!" << endl;
return 0;
}

Resolving "found '{' at file scope (missing function header?)" in VS2010 C++

I am using Visual Studio 2010 Express and I am getting the following errors for the file test.h, which when compiled outputs:
test.h(4): error C2061: syntax error : identifier 'test'
test.h(4): error C2059: syntax error : ';'
test.h(4): error C2449: found '{' at file scope (missing function header?)
test.h(18): error C2059: syntax error : '}'
The file test.h is described as follows:
#ifndef TEST_H
#define TEST_H
class test {
int a;
int b;
public:
test(int a, int b) {
this->a = a;
this->b = b;
}
int add() {
return 0;
}
};
#endif
The other file in the VS2010 project is test.c which is:
#include "test.h"
int main(int argc, char** argv) {
return 0;
}
I have a tried of multitude of ways to resolve this problem. Even if I define test.h as follows:
class test{
};
I still receive the same set of errors.
I saw a similar problem
https://stackoverflow.com/questions/7798876/strange-errors-when-using-byte-pbyte-instead-of-char-char-in-vs2k10-wdk-envi
with no response.
I will be really grateful if someone could please point out how to resolve these errors.
Thanks,
The Microsoft compiler supports both C and C++ languages, but they are not the same and need to be treated differently (for example class is no keyword in C and thus ultimately causes the error your get). So it has to somehow "know" what kind of language (C or C++) it is dealing with when compiling a source file (and thus also processing the includes).
It thinks you are trying to compile a C language file (because it has the file extension .c), while you are actually using the C++ language. Rename your file to have one of the file extensions the Microsoft C/C++ compiler recognizes as C++: .cpp, .cxx or .cc.
Alternatively, if you cannot rename the file, you can also use the /Tp command line option of cl.exe to force it to treat the file as a C++ file (for completeness /Tc would force the C language).

member hook implementation for splay_multiset in Boost::Intrusive

I was implementing boost::intrusive for one of my project on visual C++ 2008 and i stumbled upon a problem. i am using splay hooks for splay_multiset containers. I have defined splay hook publically under MyClass (code below).
#include <boost/intrusive/unordered_set.hpp>
#include <boost/intrusive/splay_set.hpp>
#include <iostream>
using namespace boost::intrusive;
class MyClass
{
int int_;
public:
MyClass(int i)
: int_(i)
{}
splay_set_member_hook<link_mode<normal_link> > memberSplayHook;
//**OPTION-1**
//PROBLEM CODE SEGMENT ++
//typedef member_hook<MyClass, splay_set_member_hook<link_mode<normal_link> >, &MyClass::memberSplayHook> MemberOption;
//typedef splay_multiset<MyClass, MemberOption> MemberMultiSet;
//PROBLEM CODE SEGMENT --
MemberMultiSet mmset;
};
//**OPTION-2**
//WORKING CODE SEGMENT ++
typedef member_hook<MyClass, splay_set_member_hook<link_mode<normal_link> >, &MyClass::memberSplayHook> MemberOption;
typedef splay_multiset<MyClass, MemberOption> MemberMultiSet;
//WORKING CODE SEGMENT --
int main()
{
return 0;
}
The problem is, to use splay_multiset, whatever option i choose (either option-1 or 2, mention in code), in both cases i see compilation errors.
When Option-1 is enabled (option-2 is commented), i see errors below:
1>d:\projects\sampleproject\sample.cpp(21) : error C2327: 'MyClass::memberSplayHook' : is not a type name, static, or enumerator
1>d:\projects\sampleproject\sample.cpp(21) : error C2065: 'memberSplayHook' : undeclared identifier
1>d:\projects\sampleproject\sample.cpp(22) : error C3203: 'member_hook' : unspecialized class template can't be used as a template argument for template parameter 'O1', expected a real type
While, when Option-2 is enabled (option-1 is commented out), i dont see undeclared identifier error msg as these errors coming with option-1. But i do see errors like below (which are obvious).
1>d:\projects\sampleproject\sample.cpp(25) : error C2146: syntax error : missing ';' before identifier 'mmset'
1>d:\projects\sampleproject\sample.cpp(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
My question is why i am getting error in first case? What can i do to get pass this issue?
Boost member hooks have (always?) been broken, since they don't compile with Visual C++.
I don't have a VS at hand to check for the precise error message so I might be wrong (but reading 'member hooks' and 'Visual C++' always triggers 'there's a problem'-mode), but do try to check this:
http://permalink.gmane.org/gmane.comp.lib.boost.user/56875
EDIT: Don't take the headline literally -- the same applies to Visual C++ 2010 and 2012. All my member hooks use this workaround; at some point I might even try to understand what it does, or more importantly, how to package it into a more comfortable setup for less "I need to find a previous implementation of this workaround so I can copy-and-modify it"...

Compiling problems with wstring in c++

I need to refactor a .dll for a Zinc based Flash application.
After copy&paste a class from the master to the branch, I'm getting some strange compiling errors:
GameInfo.h(15): error C2146: syntax error : missing ';' before identifier 'm_wsVersion'
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
The addressed code:
// removed the comments
#include "stdafx.h"
#include <string.h>
class GameInfo {
public:
UINT m_uiGameId;
wstring m_wsVersion; // Line 15
UINT m_uiCheckSum;
wstring m_wsFilePath; // Same error report as on line 15
public:
static BOOL createFromFile(wstring path, GameInfo &target); // error "error C2061: syntax error : identifier 'wstring'" thrown
};
I use Visual Studio 2010 and in the IDE itself everything is okay, no syntactical errors or something like that. And as said I did not touch the code, headers seem fine.
Has anyone a clue what about this error?
Try using the string header, and qualifying the namespace:
#include <string>
class GameInfo {
....
std::wstring m_wsVersion;
};
#include <string> is the right standard include in C++ for string classes and use std::wstring.
I strongly recommend AGAINST using a using namespace std; inside one of your headers, as you would force anybody using the header to pull in the std stuff into the global namespace.