Unix(Sun-Solaris)下FTP命令校验C程序无法运行求助
Hey there! I totally get how frustrating this must be when you're only two weeks into learning C for your Unix class—Solaris has some unique quirks that can trip up even more experienced developers, so don't feel discouraged! Let's break this down step by step to figure out why your FTP validation program compiles but won't run.
1. First, Share the Exact Error Message
When you try to execute the program, what does the terminal output say? Is it a Segmentation fault (core dumped) error, a "command not found" message, or something else entirely? That error text is critical for pinpointing what's going wrong.
2. Provide Your Full Code & Compilation Command
You mentioned the code starts with #include <...—sharing the complete code will help spot issues like missing system calls, incorrect library references, or syntax that works on other Unix systems but not Solaris. Also, tell us exactly what command you used to compile the program (e.g., cc myftp.c or gcc myftp.c -o myftp). Solaris's default cc compiler has subtle differences from GCC that might be causing problems.
3. Quick Fixes to Try Right Now
If you haven't already tested these, give them a shot:
- Run the correct executable: After compiling, you'll have an output file (usually
a.outif you didn't use the-oflag). Make sure to run it with./a.outor./your-program-name—Solaris doesn't automatically check the current directory for executables, so omitting./might cause a "command not found" error. - Link required networking libraries: FTP-related code often needs Solaris's networking libraries. Add
-lsocket -lnslto your compilation command, like this:cc ftp-check.c -o ftp-check -lsocket -lnsl - Check file permissions: Run
ls -l your-program-nameto confirm the executable has permission to run. If not, fix it withchmod +x your-program-name.
Once you share the error message and full code, we can dig into the specific issue. This is all part of learning the ins and outs of Unix and C—you're doing great just by troubleshooting this!
内容的提问来源于stack exchange,提问作者Panda King Beersy

