头文件与多源文件是否需同目录?编译执行报错求助
Let's work through this issue step by step—missing executable errors are usually easy to track down once you check a few key things. First, a quick recap: you've got a header file plus three C files (main grading system, student module, teacher module) all in an assignmentgrading3 folder, and you're hitting this error when trying to run your program from the Debug subdirectory.
Here's what to check:
First, confirm the executable actually exists in that Debug folder
Run this command to list all contents of the directory you're trying to run from:ls -la /Users/alessafaria/Documents/assignmentgrading3/assignmentgrading3/DebugLook for a file named
assignmentgrading3. If it's not there, your build failed somewhere—check your compilation commands (if building manually) or your IDE's build logs for errors like missing includes, undefined functions, or syntax issues.Make sure you're compiling all your C files correctly (manual builds)
If you're usinggccorclangin the terminal, you need to link all three.cfiles together and explicitly set the output name. For example, if your files aremain.c,student.c,teacher.c, andgrading.h, your compile command should look like this:gcc main.c student.c teacher.c -o assignmentgrading3The
-o assignmentgrading3flag tells the compiler to name your executable exactly that. If you skip this flag, the compiler will output a default executable nameda.out—so you'd need to run./a.outinstead of./assignmentgrading3.Check if you're in the right directory when running the command
The error shows you're in the Debug folder, but maybe the executable was built in the parentassignmentgrading3folder instead? Try navigating up one level and checking:cd /Users/alessafaria/Documents/assignmentgrading3/assignmentgrading3 ls -laIf you see
assignmentgrading3here, run./assignmentgrading3from this location instead.Fix execute permissions if the file exists but won't run
If you see the executable listed in the directory but still get the error, it might not have permission to run. Fix that with this command:chmod +x /Users/alessafaria/Documents/assignmentgrading3/assignmentgrading3/Debug/assignmentgrading3Then try running the program again.
Verify your IDE's build settings (if using an IDE like Xcode)
If you're using an IDE to build, double-check where it's outputting the executable. Sometimes IDEs put built files in hidden directories (like Xcode'sDerivedDatafolder) instead of the Debug folder you're looking in. Make sure your target's build settings are set to output the executable with the nameassignmentgrading3into the expected Debug directory.
内容的提问来源于stack exchange,提问作者Alessa Faria

