2 ms·
On my windows machine, running the following code: #include <stdio.h> #include <stdlib.h> int main() { puts("Hello, world"); return EXIT_SUCCESS; } with
by Alifatisk 3y ago
On my windows machine, running the following code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
puts("Hello, world");
return EXIT_SUCCESS;
}
with the following command:
dmd main.c
gives the following error:
main.c(1): Error: C preprocessor directive `#include` is not supported
main.c(1): Error: no type for declarator before `#`
main.c(2): Error: C preprocessor directive `#include` is not supported
main.c(7): Error: no type for declarator before `return`
main.c(8): Error: no type for declarator before `}`
Running the c code using docker just says that it cannot process c extensions.
docker run --rm -it -v .:/src dlanguage/dmd dmd main.c
- WalterBright 3y agoYou might be using an older version of dmd. ImportC's support for the preprocessor is fairly new.
- Alifatisk 3y ago[dead]
- Alifatisk 3y agoI got it to work on my Windows machine. The solution was that I had to install Visual studio and add the workload (plugin?) "Desktop development with c++". The only thing needed to be checked was "MSVC v143" and "Windows 11 SDK", the rest is bloat. After that I had to put the following path from Visual studio "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\Hostx64\x64" into my PATH. This is because I needed the "cl.exe", "sal.h" and probably a couple of other files to be available to dmd. (Also, the outdated version of dmd was another factor of the issue) Finally, the compilation with main.c went smoothly. I had no idea the compiler needed external tooling, I thought it was self sufficient.
- WalterBright 3y ago> I had no idea the compiler needed external tooling, I thought it was self sufficient. It used to be self-sufficient. But, we had to give up on our linker because we didn't have the staff to keep a linker up to date, and decided to stop chasing windmills and just use what was available. ImportC, in order to work, needs a preprocessor. We do have our own Standard compliant preprocessor, but it had a major problem. All the C preprocessors predefine a ton of macros (cpp predefines up to 400 macros). Different combinations of compiler switches turn on or off those predefines in poorly and usually undocumented ways. It differs from preprocessor to preprocessor, and was a hopeless nightmare. So, ImportC uses the C preprocessor of the associated C compiler, and that works like a champ. The downside is you'll need to have that preprocessor installed and on the path.
- Alifatisk 3y agoI appreciate the explanation, that makes total sense. The burden to maintain such a preprocessor doesn’t seem that rewarding compared to using existing ones.