sheredom / subprocess.h

🐜 single header process launching solution for C and C++
The Unlicense
1.14k stars 100 forks source link

MSVC linkage errors #14

Closed cdwfs closed 4 years ago

cdwfs commented 4 years ago

I'm getting linkage errors in C++ code that uses process.h; the predeclarations of various internal Windows API calls doesn't match what's eventually defined by windows.h, if both headers are included:

1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\handleapi.h(39,6): error C2732: linkage specification contradicts earlier specification for 'CloseHandle' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\handleapi.h(38): message : see declaration of 'CloseHandle' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\handleapi.h(87,6): error C2732: linkage specification contradicts earlier specification for 'SetHandleInformation' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\handleapi.h(84): message : see declaration of 'SetHandleInformation' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\namedpipeapi.h(34,6): error C2732: linkage specification contradicts earlier specification for 'CreatePipe' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\namedpipeapi.h(30): message : see declaration of 'CreatePipe' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\synchapi.h(382,6): error C2732: linkage specification contradicts earlier specification for 'WaitForSingleObject' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\synchapi.h(380): message : see declaration of 'WaitForSingleObject' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\processthreadsapi.h(154,6): error C2732: linkage specification contradicts earlier specification for 'GetExitCodeProcess' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\processthreadsapi.h(152): message : see declaration of 'GetExitCodeProcess' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\processthreadsapi.h(371,6): error C2732: linkage specification contradicts earlier specification for 'CreateProcessA' 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\processthreadsapi.h(361): message : see declaration of 'CreateProcessA'

You can reproduce the problem by adding #include <windows.h> at the end of test.cpp.

The error starts occurring in 5bdac3a7eade787; I think it has something to do with the narrowing of the extern "C" scope, which no longer includes the predeclarations. They're always defined as extern "C" in windows.h; moving them inside an extern "C" scope fixes the linkage error. Is there a reason they were moved outside that scope?

jlaumon commented 4 years ago

I got the same thing. If I include Windows.h before process.h, no problem, but if I don't, I get link errors.

eg.

error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl SetHandleInformation(void *,unsigned long,unsigned long)" (__imp_?SetHandleInformation@@YAHPEAXKK@Z) referenced in function subprocess_create

Which is weird, since process.h declares them as stdcall, not cdecl 🤔

And if I include Windows.h after, I get the same errors as you.

sheredom commented 4 years ago

On it!