Comments (14)
Compiling sokol.c as C++ only brought up a few more C++ specific /W4 warnings.
I'll reduce the 'scope' of the extern "C" more, although I don't know why my VS 2015 doesn't complain about that...
Same with the missing CINTERFACE macro (at first I suspected that this would have "spilled over" from a sokol_gfx.h include into the sokol_app.h, but in my sokol.c, sokol_app.h is included before sokol_gfx.h, so that can't be it.
Going to add those fixes now...
from sokol.
Hmm that's very weird, what version of Visual Studio are you using? The sokol headers should support VS2015 and later.
Do the normal sokol-samples build for you? (the ImGui-Samples are C++, not C)
PS: these are the Dear ImGui D3D11 / sokol_app.h samples:
https://github.com/floooh/sokol-samples/blob/master/d3d11/imgui-d3d11.cc
https://github.com/floooh/sokol-samples/blob/master/sapp/imgui-sapp.cc
from sokol.
Mine is vs2015 + update 3
yep, I tested it, and errors are same. the issue is when we try to build sokol implementation inside CPP unit, which in sokol-samples case, it was built inside C file. when I changed the compiler for sokol.c to cpp, the same errors appeared
from sokol.
Hmm I'm on VS2015 Update 5, AFAIK that was the last one. I was thinking "maybe it's the warning level", because the sokol-samples use warning level 3, so I fixed the sokol headers for warning level 4 too (ironically, the d3d11.h headers don't compile with /W4).
I have tested now on Windows7 with VS2015 (Update5) and VS2017 (Version 15.7.5), both with GL and D3D11, debug and release mode, and set the sokol-lib for the samples in the sapp-directory to warning level 4.
The only things that come to mind why you'd be getting those errors are IMHO:
- VS2015 update 3 vs update 5
- maybe a different Windows SDK version (in VS2015 it shows "8.1" for Target Platform Version, and in VS2017 the "Target Platform" is "Windows 10", and the Windows SDK Version is "10.0.17134.0"... these can be found in the Project Settings in the General tab, and seem to be the default values)
from sokol.
My windows SDK was on version 10.0.14393.0
did you try to build sokol.c with /TP (Compile as C++) flag in sapp-sokol_samples ?
the errors are only raised in this config, building the default project is ok with me too.
One build problem that I was able to figure out was with sokol_app.h
here's the complaint:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1128): error C2733: 'operator ==': second C linkage of overloaded function not allowed
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared\guiddef.h(192): note: see declaration of 'operator =='
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1133): error C2733: 'operator !=': second C linkage of overloaded function not allowed
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared\guiddef.h(197): note: see declaration of 'operator !='
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1311): error C2733: 'operator ==': second C linkage of overloaded function not allowed
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1128): note: see declaration of 'operator =='
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1316): error C2733: 'operator !=': second C linkage of overloaded function not allowed
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1133): note: see declaration of 'operator !='
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1357): error C2733: 'operator ==': second C linkage of overloaded function not allowed
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1311): note: see declaration of 'operator =='
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1362): error C2733: 'operator !=': second C linkage of overloaded function not allowed
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\d3d11.h(1316): note: see declaration of 'operator !='
the compiler actually complains about extern "C"
before some helper operators, which is sokol_app.h's fault ...
#ifdef __cplusplus
extern "C" {
#endif
....
#include <d3d11.h>
#include <dxgi.h>
...
#ifdef __cplusplus
}
#endif
I actually don't know if extern "C" is needed inside implementation.
I still can't enable d3d11's C-interfaces/macros without compiler complaining (even without sapp)
I still get errors:
error C3861: 'IDXGISwapChain_Release': identifier not found
error C3861: 'ID3D11DeviceContext_Release': identifier not found
error C3861: 'ID3D11Device_Release': identifier not found
...
Inspecting the dxgi.h and d3d11.h shows that I need to define CINTERFACE too:
dxgi.h
#if defined(__cplusplus) && !defined(CINTERFACE)
// declare cpp classes
#else /* C-Style interface */
# ifdef COBJMACROS
// declare C-style object macros
# endif
#endif
but when I defined CINTERFACE, it raised bunch of other errors that is actually SDK header's problem!!
All the helper classes doesn't count CINTERFACE to be defined, so they call non-existent functions in CINTERFACE mode.
anyway by fixing the extern "C"
and IDXGISwapChain_GetBuffer (mentioned earlier) issue in sokol_app.h and defining both CINTERFACE and D3D11_NO_HELPERS all the build errors are gone:
#define SOKOL_D3D11
#define D3D11_NO_HELPERS
#define CINTERFACE
#include "sokol_app.h"
I don't know if it fixes with the latest SDK + cpp compilation, but sorry I can't update the damn msvc right now, it's huge and risky for me
from sokol.
Ok, maybe sokol_app.h has a problem when the implementation is compiled as C++ (I think that isn't tested yet, only for sokol_gfx.h).
from sokol.
Alight, here's what I did now:
- the extern "C" is now only around the declaration parts of the headers, not in the implementation, and especially not across includes (that was indeed a bug, not sure why compilers didn't complain on my side)
- I have added the missing D3D11 config macros in sokol_app.h, and also added the linker-lib definitions there, so that it looks exactly like in sokol_gfx.h
from sokol.
Thanks.
I've updated it, but still there is one complaint on cpp:
sokol_app.h(2933): error C2664: 'HRESULT (IDXGISwapChain *,UINT,const IID &,void **)': cannot convert argument 3 from 'const IID *' to 'const IID &'
sokol_app.h(2933): note: Reason: cannot convert from 'const IID *' to 'const IID'
sokol_app.h(2933): note: No constructor could take the source type, or constructor overload resolution was ambiguous
It seems that it changes the IID* to IID& in cpp API !!
you don't get that with the latest sdk, do you ?
from sokol.
I haven't seen this yet, but I will investigate this next.
from sokol.
Here's the culprit in the Windows SDK file guiddef.h, the REFIID macro is a C++ const-ref when compiling in C++ mode, but a pointer when compiling in C mode... I don't know yet why it is like this, and what's the recommended way to deal with it (and why it still compiles here), but at least I know what to look for now...
from sokol.
yes, an example of flawed design!
maybe using a macro that put that '&' in C mode and do nothing in cpp ?
from sokol.
Ok, I could reproduce the problem also in VS2017 by directly including sokol_app.h in imgui_sapp.cc (I don't know why it didn't trigger when renaming the sokol.c file to sokol.cc though).
I fixed it like in your original suggestion (this is the only affected function call, so I think that's ok):
Let me know if this fixes everything for you, and thanks for your support so far :)
from sokol.
Thank you
keep up the great work with sokol
looking forward for better documentation, more advanced features for sokol_gfx, and android support for sokol_app..
from sokol.
noted :)
from sokol.
Related Issues (20)
- GL Shader compilation error not shown if OpenGL doesn't provide an error log
- sokol_app.h: fix scroll event values (WHEEL_DELTA vs 30.0f) HOT 1
- Remove SG_FILTER_NONE
- D3D11 backend: allow injected textures to not have a shader-resource-view.
- Add backend-specific resource info functions.
- What is the recommended version that still supports GLES2? HOT 1
- stale default framebuffer bound at end of offscreen pass HOT 5
- sokol_gfx: Issue creating render target HOT 16
- GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER: vertex attribute not found in shader (gl) HOT 3
- sokol_gfx_imgui.h depends on sokol_app.h ? HOT 4
- Compiling into a DLL with cimgui/sokol_imgui included HOT 12
- Crash in multithreaded code HOT 1
- Expose _sg_pixelformat_bytesize to users? HOT 4
- sokol_gfx: Validation error when creating offscreen pass. HOT 2
- Suggestion: Show labels in validation errors HOT 2
- Android builds without fips? HOT 4
- Help: Sampler type on per-texture basis HOT 2
- sokol-samples : `fips build` error HOT 4
- sokol_nuklear.h: how to know if nuklear handled an event HOT 3
- const void *sapp_metal_get_device(void): Assertion `_sapp.valid' failed.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sokol.