trying to get MinGW

This is a discussion on trying to get MinGW within the Tech Board forums, part of the Community Boards category; I am trying to install MinGW so that I can use Eclipse to compile C++ source code. I download MinGW ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108

    trying to get MinGW

    I am trying to install MinGW so that I can use Eclipse to compile C++ source code. I download MinGW from here and install it. When I try comping it says "error: 'printf' was not declared in this scope"

    is there a way I can attach a screen shot?
    Last edited by c_weed; 09-10-2010 at 02:20 PM.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    c_weed,

    The error means mingw is probably properly installed. That's a compilation error. Meaning it's your code that needs to be fixed.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108
    I currently don't have access to the file I was using, I'll get back to you on Monday.

  4. #4
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	printf("hello world!");
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    You are mixing C and C++ there. iostream is a strict C++ header, while printf is a C function (you can use it but you would have to include cstdio instead of iostream). Here are the tutorials for C++ provided on this site: Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy

    They should set you off nicely on your way to c++ programming.

  6. #6
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108
    Quote Originally Posted by Shakti View Post
    You are mixing C and C++ there. iostream is a strict C++ header, while printf is a C function (you can use it but you would have to include cstdio instead of iostream). Here are the tutorials for C++ provided on this site: Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy

    They should set you off nicely on your way to c++ programming.
    Shouldn't this work?

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout<<"Hello world!"<<endl;
    	return 0;
    }

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    Yes, it should. Why do you ask?
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  8. #8
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108
    When I compile using gcc.exe it gives me about 7 lines of errors. Is there a way I can insert an image of a screen shot?
    Last edited by c_weed; 09-15-2010 at 12:35 AM. Reason: added second sentence

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    You should be able to attach images. Otherwise, copy the errors.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    Quote Originally Posted by c_weed View Post
    When I compile using gcc.exe it gives me about 7 lines of errors. Is there a way I can insert an image of a screen shot?
    No need. I think I know the problem. You should be compiling with g++ -- gcc will come up with errors every time. GCC as an acronym is the GNU Compiler Collection, but gcc the program is the C compiler; g++ is the C++ compiler.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	printf("hello world!");
    	return 0;
    }
    Also, don't write stuff like this anymore. The printf function is not in iostream, but in cstdio. That was your earlier problem, provided that you used the right compiler....
    Last edited by whiteflags; 09-15-2010 at 12:11 PM.

  11. #11
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108
    Quote Originally Posted by whiteflags View Post
    No need. I think I know the problem. You should be compiling with g++ -- gcc will come up with errors every time. GCC as an acronym is the GNU Compiler Collection, but gcc the program is the C compiler; g++ is the C++ compiler.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	printf("hello world!");
    	return 0;
    }
    Also, don't write stuff like this anymore. The printf function is not in iostream, but in cstdio. That was your earlier problem, provided that you used the right compiler....
    Thanks, that was the problem. In the command line I go "g++ simple.cpp" it creates the executable but it gives me the warning "auto-importing has been activated without --enable-auto-import specified on the command line."

  12. #12
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    108
    Quote Originally Posted by whiteflags View Post
    Also, don't write stuff like this anymore. The printf function is not in iostream, but in cstdio. That was your earlier problem, provided that you used the right compiler....
    I thought printf was part of the c language and that c++ inherited all of c's functions?

  13. #13
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    Yes, it has, by inheriting stdio.h and calling it cstdio. Like I said, printf is in the cstdio header.

  14. #14
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I thought printf was part of the c language and that c++ inherited all of c's functions?
    That used to be the case, for the most part, but now there have been changes that make the two more incompatible. For instance,
    Code:
    #include <stdio.h>
    is now
    Code:
    #include <cstdio>
    . Even if you get it to work, writing new code that uses older C functions is generally discouraged, AFAIK. If you're going to write C++, using iostream's cin and cout, with the << and >> operators. If you're going to write C, then you use printf, scanf, etc..

  15. #15
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    Not to mention that the C99 standard has features that are not included in C++. So worst case you wont even be able to compile the C code because it uses features in the newer standard.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW causing problems with sprintf()
    By sedavidw in forum C Programming
    Replies: 6
    Last Post: 01-14-2010, 04:37 AM
  2. Mingw and elcipse HELP
    By Rob4226 in forum Windows Programming
    Replies: 1
    Last Post: 03-04-2008, 12:35 AM
  3. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  4. Free compiler for commercial development? (mingw?)
    By kook44 in forum Windows Programming
    Replies: 8
    Last Post: 01-07-2006, 08:32 AM
  5. compiling mingw to enable timeSetEvent
    By underthesun in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2005, 05:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21