Coder Social home page Coder Social logo

Comments (14)

floooh avatar floooh commented on July 22, 2024 1

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.

floooh avatar floooh commented on July 22, 2024

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.

septag avatar septag commented on July 22, 2024

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.

floooh avatar floooh commented on July 22, 2024

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.

septag avatar septag commented on July 22, 2024

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.

floooh avatar floooh commented on July 22, 2024

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.

floooh avatar floooh commented on July 22, 2024

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.

septag avatar septag commented on July 22, 2024

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.

floooh avatar floooh commented on July 22, 2024

I haven't seen this yet, but I will investigate this next.

from sokol.

floooh avatar floooh commented on July 22, 2024

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...
image

from sokol.

septag avatar septag commented on July 22, 2024

yes, an example of flawed design!

maybe using a macro that put that '&' in C mode and do nothing in cpp ?

from sokol.

floooh avatar floooh commented on July 22, 2024

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):

5c68e66

Let me know if this fixes everything for you, and thanks for your support so far :)

from sokol.

septag avatar septag commented on July 22, 2024

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.

floooh avatar floooh commented on July 22, 2024

noted :)

from sokol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.