Thread: Debugging C code when it depends on multiple other files

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    67

    Debugging C code when it depends on multiple other files

    Hi! My main code is written in C. The makefile I use also includes 4 other C files (3 of which are in .o format). I've been attempting to debug my main file using the Visual C++ Express Edition editor/debugger, but haven't been able to figure out how to do this; when I run my code (in executable format) in Cygwin, no output appears in the debugger's "Show Output" window, whether or not a breakpoint is set in the code. But, there is no "run" option available in the Visual C++ editor itself, to run the code outside of Cygwin.

    Does anyone have experience with debugging C code that depends on a Makefile containing other files? Which debugger do you use, and how do you accomplish your debugging?

    Given that my main C file depends upon the other 4 files, it's hard for me to comprehend debugging the main file without also somehow involving the other files, as well...

    Thanks in advance for your help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    In visual studio, add ALL source files to a project.
    Then compile the "debug" version and debug.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks for your response. Quick question: how do you compile? The Run/Play button is greyed out, and I've searched through all of the drop-down menu options, and don't see Compile (or Run) as an option. Looking through the Help files hasn't been useful; they seem only to address how to create certain types of files, rather than how to perform basic operations...

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    You need to create a project, then add the source files to that project.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks, I'll do that.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    If I have my main working directory, and then within it, a subdirectory (called \myproject) that was created when I created my project, and my .exe file is saved in *both* of these directories, why, when I attempt to Start or Debug the project, do I get the error message "Unable to start program 'myprogram.exe'. The system cannot find the file specified." ??

    The .exe file that is located in both of these directories was created using the 'make' command, using Cygwin; even if I delete these .exe files, whenever I Build the project in Visual C++, it says that the project is up to date, and never creates a new .exe file...

    Thanks for any suggestions. The Visual C++ platform/debugger is new to me, but I'm hoping that I can get the hang of it without too much trouble.

  7. #7
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Try Rebuild to force it to built it again.

    Use solely visual studio to built, don't mix make or other programs.

  8. #8
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks for the tip; Rebuild did allow the build process to reach completion.

    However, when I attempt to Start or Debug the code, I'm still receiving the same error message as before, that the .exe file can't be found; and now, despite the Build process seeming to complete, no .exe file is present in either my main directory or my project sub-directory.

    When Visual Studio's build process completes, I *should* be able to view the output .exe file in my directories, correct??

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    debug

    it could be you need to check your build targets but this sounds similar to a fault i had that requird a reinstall, if u dont want to, try creatd new project, copy content of files to new renamed files, add new files to project, rebuild, see what happens
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    When you rebuild, where does it place the executable? And is it possible you can check what executable it is trying to launch (ie path to it)?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Right now, I'm not even able to successfully complete the Build process (note: I'm trying to get this working on a different PC today); when I try to Build, I get the following error message:


    >------ Build started: Project: debug_8-12, Configuration: Debug Win32 ------
    1>Embedding manifest...
    1>mt.exe : general error c10100b1: Failed to load file "..\Debug\debug_8-12.exe". The system cannot find the path specified.
    1>Build log was saved at "file://c:\temp\8-12-10\Debug\debug_8-12\debug_8-12\Debug\BuildLog.htm"
    1>debug_8-12 - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    I don't understand the error "Failed to load file "..\Debug\debug_8-12.exe"; first of all, there *was* no folder named \Debug within my working folder, but I created one anyway in case it needed to exist. (I pasted my project folder within this \Debug folder). However, I still get the exact same error. Am I supposed to somehow *create* this debug_8-12.exe file? It's not one of my code files within my project...

    I also drastically shortened my working directory's path name, in response to the "cannot find the path name specified error"; but the error above continues to occur, despite the changes I've made.

    Any ideas??
    Last edited by CodeKate; 08-12-2010 at 10:57 AM.

  12. #12
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    ide

    debug folder is probably created by default in build settings. the only exe you can put in is one you program, u cannot just name a file .exe and expect something to happen. troubleshoot by makin new simple hello world project, compile, run, run in debug mode, if fail reinstall ide, or seek altermative ide to compare
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  13. #13
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks, rogster.

    >> debug folder is probably created by default in build settings. the only exe you can put in is one you program, u cannot just name a file .exe and expect something to happen.

    No, I didn't change any file extension to .exe; rather, if my own executable is supposed to be named "mycode.exe", I'm wondering why the error message is referring to an executable named "debug_8-12.exe", where "debug_8-12" is the name of my *folder*, not of my *code*.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your project is named debug_8-12. Therefore, VS would create the hiearchy debug_8-12\Debug\debug_8-12.exe by default.
    Probably your settings are corrupted. Try a new project and test. That might be the best solution.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to handle multiple cases which use common code?
    By tmaxx in forum C Programming
    Replies: 3
    Last Post: 10-03-2008, 07:42 AM
  2. Splitting Code Into Multiple Files
    By pobri19 in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2008, 04:21 AM
  3. Packed Files (Puting multiple files in one file)
    By MrKnights in forum C++ Programming
    Replies: 17
    Last Post: 07-22-2007, 04:21 PM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Replies: 8
    Last Post: 04-28-2003, 07:29 PM