Thread: Code failing to create file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4,183

    Code failing to create file

    I am trying to build some third party code that is an compiler for the old MC6809 CPU.

    Code:
            /*  Create an asm file that will receive the assembly language code:
            */
            if (numErrors == 0)
            {
                if (verbose)
                {
                    cout << "Assembly language filename: " << asmFilename << "\n";
                    cout << flush;
                }
                ofstream asmFile(asmFilename.c_str(), ios::out);
                if (!asmFile)
                {
                    int e = errno;
                    cout << PACKAGE << fatalErrorPrefix << "failed to create assembler file " << asmFilename
                         << ": " << strerror(e) << endl;
                    return EXIT_FAILURE;
                }
                if (!asmText.writeFile(asmFile))
                {
                    cout << PACKAGE << fatalErrorPrefix << "failed to write output assembly file " << asmFilename << endl;
                    return EXIT_FAILURE;
                }
                asmFile.close();
                if (!asmFile)
                {
                    cout << PACKAGE << fatalErrorPrefix << "failed to close output assembly file " << asmFilename << endl;
                    return EXIT_FAILURE;
                }
            }
    
            if (verbose)
                cout << numErrors << " error(s)"
                        << ", " << numWarnings << " warning(s)." << endl;
    The output from this section of code and the sub-program it calls is
    Code:
    Assembly language filename: atol.s
    0 error(s), 0 warning(s).
    Assembler command: lwasm -fobj --pragma=forwardrefmax -D_COCO_BASIC_ --output='atol.o' 'atol.s'
    Cannot open file ''atol.s'': No such file or directory
    Exit code from assembler command: 1
    Any suggestion of code to add to trace the problem; it is a large program built using configure/make so using debugger would like be beyond me.

    Edit: I have search the file atol.s does not exist.
    Edit2: I am thinking this test "if (!asmFile)" is not correct.
    Edit3: Link to full file cmoc/main.cpp at master * stahta01/cmoc * GitHub
    The snippet posted is around line 1250.
    Edit4: I am porting the code to work under Windows 10; it is designed for Linux; but, has worked in the past under windows with, unknown to me, minor changes.

    Tim S.
    Last edited by stahta01; 04-26-2023 at 07:29 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. N00b @ C: Code is failing at line 12 which is a basic scanf
    By Mike Garber in forum C Programming
    Replies: 3
    Last Post: 09-01-2013, 10:25 AM
  2. Replies: 10
    Last Post: 05-14-2013, 07:49 PM
  3. fread failing to read full file
    By DeusAduro in forum C Programming
    Replies: 3
    Last Post: 05-27-2009, 12:21 PM
  4. Failing to open() a file
    By sa125 in forum C Programming
    Replies: 4
    Last Post: 07-31-2008, 11:37 PM
  5. program failing while trying to open/create file
    By 1978Corvette in forum C Programming
    Replies: 17
    Last Post: 04-26-2006, 10:55 AM

Tags for this Thread