r/C_Programming • u/water_jello8235 • Sep 09 '26
Question Why do I fail to create a .dll file?
Hi, I've got an assignment in a course that asks us to optimize a benchmark of our selection (from pyperformance project).
I've chosen the ray trace benchmark (it was the most interesting imo), and my suggestion was to implement the functionality using C's structs to avoid some of the interpreter's overhead.
I understood I can link those function using the built-in ctypes library, and making the C file a dynamic linked library (.dll), but when I try to run the command for it in CLion or VSC, it fails without returning any failure message, it just fails to generate the .dll file.
The assignment forces us to use the given pyperf benchmark code to run the benchmark, so I can't run only a C file.
I've already written the C code, and it has no errors/warnings so far (at least as far as CLion is concerned), and the original python code works too.
Does anyone know how to solve the library not being generated? Or any other solution that might work (preferrably using the C code I've made)?
.
.
All files are in the same directory, and I've got Craytrace.c (C functionality implementation), Praytrace.py (the code that runs the benchmark).
The command I've run trying to generate the .dll is:
gcc -shared -o CraytracerLib.dll Craytrace.cBut it didn't create any file.
.
.
.
Edit:
Ok, so apparently I'm stupid for assuming that running a file in CLion meant that gcc in the terminal worked, I went to the terminal's environment's variables, added the path of the CLion's gcc and it worked.
Ig, the gcc I had before was a wrong path.
Thanks for everyone for answering 🙏 .
14
u/[deleted] Sep 10 '26
How did you test that? I'd normally do 'dir/od' in the same directory to see the last file created.
Your command line looks correct; were there any compiler messages?
I assume you know that gcc is correctly working otherwise (eg. it might be some rogue file called gcc.exe or gcc.bat which it finds first in the OS's search path).
5
u/sciencekm Sep 10 '26
Assuming you are using MinGW, you need to:
Here is an very short example that demonstrates everything needed.
2
u/mort96 Sep 10 '26
We're gonna need a screenshot of you running the command using 'fit' afterward to list the directory. Impossible to debug "it didn't work" without additional info.
2
u/Ice_HRZDn Sep 09 '26
This might be a dumb idea from unexperienced person (me) but have you try -c flags? gcc -shared -o lib.dll -c lib.c
-8
u/SoggyStress7785 Sep 10 '26
Follow the Microsoft tutorial and use VS to create a .dll, why the fuck are you using gcc to create a .dll
-10
u/nanaceba Sep 09 '26
Use cmake