visuald icon indicating copy to clipboard operation
visuald copied to clipboard

Struggling with ImportC

Open TurkeyMan opened this issue 4 months ago • 20 comments

So I added a .c file to my project

#pragma attribute(push, nothrow, nogc)

#if defined(_WIN32)
# include "pcap.h"
#endif

By default, Visual Studio treats it as a C/C++ file and hands it to cl.exe for compiling. So, I change the file's Item Type to "D Compile", which matches all the D source files: Image That kinda seemed to have some effect, now when I build, the file is included in the DMD command line:

1>Compiling appliance.d [...] variant.d zip.d os.c  # <-- NOTE THE os.c FILE HERE
1>COMPILED : error : C preprocess command C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\cl.exe failed for file third_party\urt\src\urt\internal\os.c, exit status 2
1>
1>third_party\urt\src\urt\internal\os.c(12): fatal error C1083: Cannot open include file: 'pcap.h': No such file or directory

But you can see from that build output, it invokes DMD (apparently correctly), and then it seems to try and build it with cl.exe as well??

Or, is that output coming from pipelink.exe (or whatever it's called) and it is delegating the .c file out to the C compiler before it reackes DMD?

Surprisingly, it complains because it can't find the include path, so it seems cl.exe is definitely invoked and trying to build the file; but the error is surprising, because the C/C++ compiler config actually DOES specify the correct include path. If I change that file back to "C/C++ compiler" and let the C compiler compile it, it does compile properly in that case.

So, I guess something is just askew when forcing a .c file to use the D Compiled item type...

TurkeyMan avatar Aug 25 '25 03:08 TurkeyMan