So I was following instructions on a book to create a d3d object. However, when I tried to compile the codes, it gives me some weird error in d3d11shader.h.
Inside the d3dshader.h,
#include "d3dcommon.h"
//other stuff
typedef struct _D3D11_SIGNATURE_PARAMETER_DESC
{
LPCSTR SemanticName;
UINT SemanticIndex;
UINT Register;
D3D_NAME SystemValueType;
D3D_REGISTER_COMPONENT_TYPE ComponentType;
BYTE Mask;
BYTE ReadWriteMask;
UINT Stream;
D3D_MIN_PRECISION MinPrecision; //Errors here
} D3D11_SIGNATURE_PARAMETER_DESC;
For details:
(1) Error 29 error C2146: syntax error : missing ';' before identifier 'MinPrecision' c:\program files (x86)\windows kits\8.0\include\um\d3d11shader.h 54
(2) Error 30 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\windows kits\8.0\include\um\d3d11shader.h 54
It's weird cause both d3dcommon.h and d3d11shader.h files are defined in Windows SDK and DirectX SDK so I couldn't change anything in them. Can anyone tell me how to fix it? Any input is appreciated here.
Here is the codes in my Source.cpp which are directly copied from the book 3D Game Programming with DirectX11 by Frank Luna.
#include "d3dApp.h"//This header file is provided by the book
class InitDirect3DApp : public D3DApp
{
public:
InitDirect3DApp(HINSTANCE hInstance);
~InitDirect3DApp();
bool Init();
void OnResize();
void UpdateScene(float dt);
void DrawScene();
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR cmdLine, int showCmd)
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
InitDirect3DApp theApp(hInstance);
if( !theApp.Init() )
return 0;
return theApp.Run();
}
Init Direct3DApp::InitDirect3DApp(HINSTANCE hInstance)
: D3DApp(hInstance)
{
}
InitDirect3DApp::~InitDirect3DApp()
{
}
bool InitDirect3DApp::Init()
{
if(!D3DApp::Init())
return false;
return true;
}
void InitDirect3DApp::OnResize()
{
D3DApp::OnResize();
}
void InitDirect3DApp::UpdateScene(float dt)
{
}
void InitDirect3DApp::DrawScene()
{
assert(md3dImmediateContext);
assert(mSwapChain);
md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Blue));
md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
HR(mSwapChain->Present(0, 0));
}
And another weird thing I've noticed is that sometimes when I go to the definition of D3D_MIN_PRECISION and it directs me to d3dcommon.h, the codes in d3dcommon.h are not highlighted at all. Visual Studio does highlightings for all other files automatically but not for this one.. So I just assume it doesn't recognize the codes in this specific header file some time..
Also, as I tried to compile the codes just now, there's another error popping out in addition to the previous two:
31 IntelliSense: identifier "D3D_MIN_PRECISION" is undefined c:\Program Files (x86)\Windows Kits\8.0\Include\um\d3d11shader.h 54
Just for your information, I'm using vs2012 on a windows 8.1 machine. Thanks a lot!
Your problem is most likely that you are mixing the Windows 8.x SDK and legacy DirectX SDK headers incorrectly.
Historically you would set the INCLUDE and LIB paths so that the DXSDK_DIR was first, but that only worked when the DirectX SDK headers were current. Now that they are out-dated, you need to use the WindowsSdkDir before the DXSDK_DIR (assuming you need to use stuff like D3DX that is deprecated that only available in the legacy DirectX SDK; otherwise you wouldn't need it at all).
With VS 2012's "v110" or VS 2013's "v120" Platform Toolset, if you also need to use the DirectX SDK, you use VC++ Directory settings for Include and Lib of:
$(IncludePath);$(DXSDK_DIR)Include
$(LibraryPath);$(DXSDK_DIR)Lib\<x86 or x64>
See MSDN, Living Without D3DX, XInput, and XAudio
BTW, If you were trying to use VS 2012's "v110_xp" or VS 2013's "v120_xp" Platform Toolset, it works more like it did in the old days and would use the traditional order. See this blog post.
$(DXSDK_DIR)Include;$(IncludePath);
$(DXSDK_DIR)Lib\<x86 or x64>;$(LibraryPath)
Related
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.
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.
Getting error i freetds headers when i include them in my VS 2017 c++ project
in tds.h when i include that in my project
include\tds.h(1331): error C3646: 's': unknown override specifier
include\tds.h(1331): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\tds.h(1641): error C2065: 'TDS_SYS_SOCKET': undeclared identifier
include\tds.h(1641): error C2146: syntax error: missing ')' before identifier 's'
I am trying to use freetds 0.91.100 version in my c++ application which was built using VS 2010. It was fine then.
Now after migrating my C++ project to VS 2017 i am getting strange errors.
I have built freetds lib as well in VS 2017.
freetds has this declaration in tds_sysdep_private.h
#if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32)
typedef int TDS_SYS_SOCKET;
#define INVALID_SOCKET -1
#define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
#else
typedef SOCKET TDS_SYS_SOCKET;
#define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
#endif
and the tds.h has
struct tds_socket
{
TDS_SYS_SOCKET s; /**< tcp socket, INVALID_SOCKET if not connected */
}
And the error is on this TDS_SYS_SOCKET declaration
My code include this header this way.
tdsloader.h
using namespace std;
#if defined (__cplusplus)
extern "C" {
#endif
#include "tds.h"
#if defined (__cplusplus)
}
#endif
As per the declaration of TDS_SYS_SOCKET in tds_sysdep_private.h , in case of windows build it is defined as SOCKET which is from winsock2.h
I read in other threads that the order of header file includion is important and i made sure that winsock2.h is included before windows.h or any other windows header file.
Now that SOCKET from winsock2.h is
typedef UINT_PTR SOCKET;
which in an unsigned , why is VS 2017 not able to recognize the type ?
Build should go through smoothly as it did in VS 2010.
Now with VS 2017 it shows build errors.
Here's the include order that works fine with VS 2017:
#include <tds_sysdep_private.h>
#include <tds.h>
alternatively you can:
#define _FREETDS_LIBRARY_SOURCE
#include <tds.h>
I am trying to program a C++ Wrapper for TWAIN with Visual Studio 2012, Windows 7.
I have installed Twain SDK and have all DLL like Twain_32.dll in C:/Windows
I have twain.h : https://svn.apache.org/repos/asf/incubator/ooo/trunk/main/twain/inc/twain.h
And I have my main :
#include <windows.h>
#include "twain.h"
int main()
{
return 0;
}
And I get 200 errors like for this line
#ifdef _MSWIN_
typedef HANDLE TW_HANDLE;
typedef LPVOID TW_MEMREF;
error C2146: syntax error : missing ';' before identifier 'TW_HANDLE'
How can I resolve that ?
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.