Thread: Problem building a Release

  1. #1
    C++ SharK The SharK's Avatar
    Join Date
    Mar 2004
    Location
    Denmark
    Posts
    62

    Question Problem building a Release

    When I build this code, as a Release version using Visual Studio Express 2005, it compile this code as (8.704 bytes),
    but the file doesn't run on other machines ?


    Code:
    // This is a simple counter ;-)
    
    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    
    
    int main()
    {
    	int i = 1;
    	int input = 123;
    
    	std::cout << "Counter by The SharK" << std::endl << std::endl;
    	Sleep (2000);
    	std::cout << "Input Password ;-) " << std::endl;
    	Sleep(3000);
    	std::cout << "Pssst.... it's three numbers !" << std::endl;
    	Sleep(5000);
    	std::cout << "The password is 12?" << std::endl;
    	std::cin >> input;
    
    	if ( input == 123 )
    		{
        	std::cout << "CORRECT password !";
    		for ( i = 1 ; i >= 0 ; ++i )
    			std::cout << i << std::endl;
    		Sleep(5000);
    		}
    	std::cout << "WRONG password :-(" << std::endl;
        std::cout << "Press [Enter] to continue" << std::endl;
    
    	// To force [ENTER]
    	std::cin.get();
    	std::cin.get();
    	return(0);
    }

    Can any of you make a release of this code, which works
    on any windows xp machine
    Studying programming languages,
    you'll ALWAYS be a student ;-)

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    You have 2 choices, create a setup application that installs the necessary dll's (minimally msvcrt80.dll) for use on other machine... or link your application statically. I prefer the second in most situations. In VS2005 the setting is: Project->Properties->C/C++ -> Code Generation -> Runtime Library. Set it to Multi-Threaded. The default is multi-threaded DLL.

  3. #3
    C++ SharK The SharK's Avatar
    Join Date
    Mar 2004
    Location
    Denmark
    Posts
    62
    Hi Darryl


    In VS2005 the setting is: Project->Properties->C/C++ -> Code Generation -> Runtime Library. Set it to Multi-Threaded. The default is multi-threaded DLL.
    That sure did the job, great thanks Darryl


    ... or link your application statically
    What's the big difference between linking statically and I guess dynamically
    I mean, I wasn't gonna build a DLL, just a normal EXE file....
    Studying programming languages,
    you'll ALWAYS be a student ;-)

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>I mean, I wasn't gonna build a DLL, just a normal EXE file....
    Quick rundown:
    Doesn't matter. If your code accesses an external library's function, then the library must be linked with your executable (i.e. the library is precompiled, you're not directly injecting the library's C/C++ code into your own). If you link statically, then the code from the library is added to your exe file in the linking stage, and you eliminate the external dependency. If you link dynamically, then you'll need the .dll file of the library to be present on the user's system, but you will have a smaller .exe file, and the user is free to use a different (i.e. updated or optimized) version of the library by supplying their own .dll file.

    **EDIT**
    >>and I guess dynamically
    Yep, that's what it's called. DLL stands for 'Dynamically Linked Library', and I'm sure you can see where the name comes from.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    C++ SharK The SharK's Avatar
    Join Date
    Mar 2004
    Location
    Denmark
    Posts
    62
    Thanks Hunter2

    for setting things straight, nice explanation
    Studying programming languages,
    you'll ALWAYS be a student ;-)

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    23
    I have Visual C++ Express Edition and can't compile this code. It says that stdafx.h does not exist. If I comment out that line, it says that it can't find windows.h.

    Is it possible for me to get it to compile (and then transfer to any XP computer) with my software? What am I doing wrong?

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> it says that it can't find windows.h

    You sure about that?

  8. #8
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by CondorMan
    I have Visual C++ Express Edition and can't compile this code. It says that stdafx.h does not exist. If I comment out that line, it says that it can't find windows.h.

    Is it possible for me to get it to compile (and then transfer to any XP computer) with my software? What am I doing wrong?
    You need to turn off precompiled headers.
    Project->Properties->Config Properties->c/c++->Precompiled Headers->Create/Use Precomiled Headers.

    Change to "Not Using Precompiled Headers"


    In the future, when you start a new project there is a setting during the project creation wizard to use pre-compiled headers, uncheck it.

  9. #9
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>it can't find windows.h<<

    You need to install the psdk and add the paths to its directories to the compiler's settings.

    http://msdn.microsoft.com/vstudio/ex...alc/usingpsdk/
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  10. #10
    Registered User
    Join Date
    Jun 2006
    Posts
    23
    Thank you Darryl and Ken. I'll follow your instructions.

  11. #11
    Registered User
    Join Date
    Jun 2006
    Posts
    23
    Wow - after a lengthy session connected to the site, I've managed to install psdk. I've also added the following paths within Tools>Options>VC++ Directories:

    Executable files - C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin

    Include files - C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include

    Library files - C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib

    The code at the beginning of this thread still doesn't compile. It gives the error:

    "Cannot open include file: 'stdafx.h': No such file or directory"

    If I comment out that line, it compiles without an error so it is finding the window.h file that it couldn't find before. When I run it, it seems to work fine in that it asks for the password and then starts to generate numbers in increasing order.

    I assume that the "stdafx.h" file is one that The Shark wrote and had in the project at compile time. As it seems not to be needed for this code to run correctly, do I need to be concerned?

    A final (very simple!) clarification question - am I right in thinking that the #include files in angle brackets are there already and "built in" to the compiler/linker and those which are in double inverted commas have been written by the person who created the code and, as such, need to be added as a source file in the project?

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    A final (very simple!) clarification question - am I right in thinking that the #include files in angle brackets are there already and "built in" to the compiler/linker and those which are in double inverted commas have been written by the person who created the code and, as such, need to be added as a source file in the project?
    Pretty much yes. The angle brackets are more for standard headers, actually. Also, you may want to add the user defined header files to the list of header files in the project rather than the list of source files.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    As for the stdafx header, it is showing because you didn't uncheck "create precompiled header files" when creating your project.

    Once your project is created you can do this through the menu:

    Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Precompiled Headers.

    Change "Create/Use Precompiled header" to not using precompiled headers.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #14
    Registered User
    Join Date
    Jun 2006
    Posts
    23
    Thank you laserlight and Mario F.

    The setting "Create/Use Precompiled header" was already at "not using precompiled headers"! I tried toggling it in both directions and closed down between changing the settings but it still doesn't like the reference to stdafx.h.

    Any other ideas?

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Well, the idea is to remove the header altogether

    Remove it and make sure you have your project set not to use precompiled headers. On those next projects you come to create, make sure you uncheck the tick box "use precompiled headers" on the project creation screen.

    You don't need the stdfax header.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Mesh Release() Problem
    By Morgul in forum Game Programming
    Replies: 6
    Last Post: 03-07-2006, 02:50 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM