Thread: First Windows Application Tutorial. stdfx.h: No such file or directory

  1. #1
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23

    First Windows Application Tutorial. stdfx.h: No such file or directory

    Hi, I'm trying to follow rods First Windows Application Tutorial. (from the tuts section on this site)

    but I get an error

    error: stdfx.h: No such file or directory

    I also have a warning "ignoring #pragma comment"

    do you more knowledgeable than me peeps have any ideas to help me resolve this please?
    Last edited by Brian_of_Bozeat; 12-09-2011 at 07:55 AM. Reason: speeeling meeestake

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    What compiler are you using?

    Jim

  3. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Oh, sorry - I'm using code blocks 10.05 with the default GNU GCC compiler.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    If it contains "stdafx.h", it is probably a MSVC project.

    The proper name is stdafx.h. Check if this is correct.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Yes indeed, my apologies:


    #include "stdafx.h" is the line it chokes on. I copied and pasted it this time.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    You are using Code::Blocks so you do not need to include stdafx.h. This is a Microsoft specific include file. Also gcc, the compiler that Code::Blocks is using may not support the #pragma directives.

    Jim

  7. #7
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Thanks Jim for your help, Looks like I'm shafted - I'm pretty frustrated right now, I set aside an afternoon to do this tutorial, to be honest I'm bored with making console applications and I want to move on to making GUI type programs - Can you suggest a productive way for me to move in this direction this afternoon/evening?

    btw. The tutorial didn't mention needing any "special" files, and the previous "hello world" example worked OK. I guess I'll have to search for a tutorial that works with code blocks, I know theres templates for win32 apps in codeblocks but I dont understand them so was trying to learn - How annoying, trying to learn a language seems to be more about learning about IDE's and compilers - I thought I read that C++ was portable and was a standardised language?

    After reading your post I 'commented out' each sticking point in turn. In case its of any use to anyone, here's the other lines that the IDE/Compiler stopped at.

    SetTextColor(hDC, COLORREF(0x00FF0000));
    TextOut(hDC,150,150,string,sizeof(string)-1);
    GetStockObject(WHITE_BRUSH);

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Without seeing the code that is causing the problem I can't help much. But the three lines you show should compile correctly, as long as the correct include files are included since they are part of the Windows API. If you post the code causing the problems, or a link to the tutorial in question, along with the complete error messages, exactly as they appear in your development environment. Someone may be able to help.

    Jim

  9. #9
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    > I thought I read that C++ was portable and was a standardised language?
    Of course it is... but the Windows API isn't.
    As long as you stick to standard C++ and Portable libraries, everything ought to work everywhere...provided you set up the environment correctly .

  10. #10
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Thanks again Jim.A First Windows Application - Cprogramming.com

    is the tutorial

    Error messages: (after commenting out the stdafx.h line)

    C:\Users\Brian\Documents\codeblocksProjects\WINTUT \main.cpp|3|warning: ignoring #pragma comment |
    obj\Debug\main.o||In function `Z7WndProcP6HWND__jjl@16':|
    C:\Users\Brian\Documents\codeblocksProjects\WINTUT \main.cpp|31|undefined reference to `SetTextColor@8'|
    C:\Users\Brian\Documents\codeblocksProjects\WINTUT \main.cpp|33|undefined reference to `TextOutA@20'|
    obj\Debug\main.o||In function `WinMain@16':|
    C:\Users\Brian\Documents\codeblocksProjects\WINTUT \main.cpp|61|undefined reference to `GetStockObject@4'|
    ||=== Build finished: 3 errors, 1 warnings ===|

  11. #11
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Quote Originally Posted by manasij7479 View Post
    > I thought I read that C++ was portable and was a standardised language?
    Of course it is... but the Windows API isn't.
    As long as you stick to standard C++ and Portable libraries, everything ought to work everywhere...provided you set up the environment correctly .
    Thanks, I'm sure your post is correct, but how does one "stick to standard C++ and Portable libraries & set up the environment correctly"? its a chicken and egg situation for me as I'm trying to get started but spending more time working around IDE/compiler problems than writing/learning code. I didn't take this up (again) because I wanted to be an IT troubleshooter - I just remembered how much fun I had a s a teenager writing BASIC programs and such like... Perhaps C++ is not for me?

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    These errors seem to be linker errors. How did you create your project for this program? What type of program did you tell the IDE to create, a console app or a Win32 app?

    Jim

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    The below line is an Visual C++ only line.

    Code:
    #pragma comment(linker, "/subsystem:windows")
    To fix you need to add the linker option for MinGW GCC that matches the above option.

    from Compiling Windows GUI Application With MinGW Without Command Prompt

    The old option was this
    Code:
    -mwindows
    It was replaced in newer version of MinGW GCC with
    Code:
    -Wl,-subsystem,windows
    I suggest finding directions for the same Compiler (MinGW GCC) you are using; the frustrations will be much less. Or, changing to use the Compiler in your directions.

    Tim S.

  14. #14
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Quote Originally Posted by jimblumberg View Post
    These errors seem to be linker errors. How did you create your project for this program? What type of program did you tell the IDE to create, a console app or a Win32 app?

    Jim
    Jim - you are a star!

    OK, so here's what happened. I started a new win32 project (dialogue based, if that makes any difference) then deleted everything except the main source file. I then deleted all the code and pasted in the code from the tutorial - after that I removed the #pragma comment(linker, "/subsystem:windows") and #include "stdafx.h" lines and it worked.

    Tim. S: I read everythjing in your post and link, but I am not sure that I'm any wiser! Is it something to do with the "make file"? what on earth is that?

    Thanks again. Looks like I did learn something this afternoon, but not what I intended, lets hope I can move forward at my next session!

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Brian_of_Bozeat View Post
    Thanks, I'm sure your post is correct, but how does one "stick to standard C++ and Portable libraries & set up the environment correctly"? its a chicken and egg situation for me as I'm trying to get started but spending more time working around IDE/compiler problems than writing/learning code. I didn't take this up (again) because I wanted to be an IT troubleshooter - I just remembered how much fun I had a s a teenager writing BASIC programs and such like... Perhaps C++ is not for me?
    Unfortunately, there is no standardized UI for C++, so it will be a little slow to get started since you have to learn all the tricks and solutions people have come up with to make things work.
    Ideally, after this everything will be fine. But C++ can be a tricky language for newbies. If you are still content with this (seeking help a little now and then), then C++ is fine.

    Now, I really suggest you drop the Win32 API tutorial and go download Qt. It's written for C++, it's portable and it's a heck of a lot simpler than the Win32 API (which is a mess).
    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. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. windows.h no such file or directory
    By FingerPrint in forum Tech Board
    Replies: 11
    Last Post: 08-26-2006, 09:51 PM
  3. a question about the windows application tutorial
    By JustPlay4Fun in forum Windows Programming
    Replies: 4
    Last Post: 01-17-2005, 01:09 PM
  4. Replies: 2
    Last Post: 09-27-2003, 11:57 AM