Jump to content

  • Log In with Google      Sign In   
  • Create Account


Change the compiler of c++ 11


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#1 Sugavanas   Members   -  Reputation: 166

Like
0Likes
Like

Posted 23 November 2012 - 05:02 AM

How do i change the compiler of C++ 11 in VS12 to codeblocks compiler

Sponsor:

#2 Radikalizm   Crossbones+   -  Reputation: 2805

Like
7Likes
Like

Posted 23 November 2012 - 05:18 AM

Why would you even want to do this? What's wrong with the MSVC compiler provided with VS2012?
If you are still taking your first steps in C++ any modern compiler will do, if you're facing any problems they're most likely due to your own setup, not because of compiler issues.

Learning C++ can be a huge mindf*ck in itself, don't make things even worse for yourself by trying to mess with custom build settings.

I gets all your texture budgets!


#3 Bacterius   Crossbones+   -  Reputation: 8352

Like
6Likes
Like

Posted 23 November 2012 - 05:21 AM

There is no "codeblocks compiler", did you mean gcc? If so, it does not exist as such under Windows, but you can use MinGW which is a POSIX wrapper to run gcc on windows. Then you just indicate the correct bin, lib, include folders in your VS12 settings and you are good to go. Be wary that debugging may not work, and you may also have problems if you try to use a 64-bit compiler with a 32-bit IDE (or even with a 64-bit IDE for that matter). I agree with Radikalizm and unless there is a strong reason you need to change compilers, don't do it.

Edited by Bacterius, 23 November 2012 - 05:22 AM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#4 Sugavanas   Members   -  Reputation: 166

Like
0Likes
Like

Posted 23 November 2012 - 06:03 AM

Thanks but i want to change the compiler because I use a book which uses c++ to teach but i feel comfortable using vs 12 and i also need the same results as it is in code blocks. thats why

#5 Brother Bob   Moderators   -  Reputation: 7928

Like
0Likes
Like

Posted 23 November 2012 - 06:15 AM

What is it with the result from VS2012 that is different from codeblocks, or not what you expect or want it to be?

#6 Sugavanas   Members   -  Reputation: 166

Like
0Likes
Like

Posted 23 November 2012 - 06:27 AM

The thing is in codeblocks the console does not end after it starts but in vs it just closes and i can't see a thing, for example use this code in vs and codeblocks in an console app,
#include <iostream>
using namespace std;
int main()
{
    //Chapter 2 : Additon code

    //Chapter 2 : Divisional code
	  int first, second;
	  cout << "Dividing 28 by 14." << endl;
	  first = 28;
	  second = 14;
	  cout << "Quotient  " << first / second << endl;
	  cout << "Remainder " << first % second << endl;
	  cout << "Dividing 32 by 6." << endl;
	  first = 32;
	  second = 6;
	  cout << "Quotient  " << first / second << endl;
	  cout << "Remainder " << first % second << endl;
		    //chapter 2 : char
	  cout << "Char  " << first / second << endl;
	  char ch;
	  ch = 'a';
	  cout << ch << endl;
	  char c;
	  c = '\0';
	  cout << c << endl;
	  cout << "hif" << endl;
	  return 0;

}


#7 LennyLen   Crossbones+   -  Reputation: 3613

Like
5Likes
Like

Posted 23 November 2012 - 06:36 AM

Use CTRL-F5 to start the application inside VS, and the console should remain open.

edit: You also need to do the following steps (copied from a Stack Overflow answer):


Note that this requires the Console (/SUBSYSTEM:CONSOLE) linker option, which you can enable as follows:
1 Open up your project, and go to the Solution Explorer. If you're following along with me in K&R, your "Solution" will be 'hello' with 1 project under it, also 'hello' in bold.
2 Right click on the 'hello" (or whatever your project name is.)
3 Choose "Properties" from the context menu.
4 Choose Configuration Properties>Linker>System.
5 For the "Subsystem" property in the right-hand pane, click the drop-down box in the right hand column.
6 Choose "Console (/SUBSYSTEM:CONSOLE)"
7 Click Apply, wait for it to finish doing whatever it does, then click OK. (If "Apply" is grayed out, choose some other subsystem option, click Apply, then go back and apply the console option. My experience is that OK by itself won't work.)

Edited by LennyLen, 23 November 2012 - 06:38 AM.


#8 Sugavanas   Members   -  Reputation: 166

Like
0Likes
Like

Posted 23 November 2012 - 06:39 AM

Ya it is there but when u close it and juz use F5 it closes automatically

#9 Brother Bob   Moderators   -  Reputation: 7928

Like
2Likes
Like

Posted 23 November 2012 - 06:43 AM

As LennyLen said, you can keep the console open after exit in VS also. This is not the result of the compiler, but the result of how the IDE handles your application. So even if you would have used the VS IDE with another compiler, it is still VS that is either keeping the console open or closing it after the program exits.

For example, in VS you can run the application with (F5) or without (CTRL-F5) the debugger. If you run the application with the debugger, the IDE will close the console immediately, and if you run it without the debugger, it will keep the console open after it exits.

#10 SiCrane   Moderators   -  Reputation: 9501

Like
2Likes
Like

Posted 23 November 2012 - 08:02 AM

Alternately you can just set a break point at the closing brace for the main() function. Just click the margin on the left of the closing brace in the IDE.

#11 lride   Members   -  Reputation: 633

Like
2Likes
Like

Posted 23 November 2012 - 08:20 AM

Put std::cin.get() (maybe one more) at the end of your program to pause.
An invisible text.

#12 kauna   Crossbones+   -  Reputation: 2290

Like
2Likes
Like

Posted 23 November 2012 - 08:22 AM

Alternatively you can pause your program at the end using something like std::cin.get(); or getchar();

Cheers!

#13 NightCreature83   Crossbones+   -  Reputation: 2706

Like
0Likes
Like

Posted 23 November 2012 - 10:15 AM

If this is a windows only application you can add the following line at the bottom of the main
 stytem( "pause" );

Otherwise should work on any system
std::cout << "press the enter key to continue" << std::endl;
char c;
std::cin >> c;

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#14 BigDaveDev   Members   -  Reputation: 131

Like
1Likes
Like

Posted 25 November 2012 - 01:15 PM

I really can't recommend against
system("pause");
enough. Especially when you can have highly portable functions available to you in the standard library.

I prefer to use something like:
void pause_console(char const* message)
{
   std::cout << message << std::flush;
   std::cin.ignore(std::numeric_limits< std::streamsize >::max(), '\n');
}

Benefits? Independent of IDE in use and is platform independent.

Incidentally, the MSVC compiler in VS2012 is perfectly fine. I would recommend sticking with it on the Windows platform. In fact, the only reason I use g++ on Windows is to experiment with variadic templates among other things that VS doesn't yet support. For the simple stuff, though, don't sweat over compiler differences too much. Your results should be the same regardless.
Cows would last a lot longer if they weren't made of steak and leather.

Check out my site: bigdavedev.com

#15 noizex   Members   -  Reputation: 854

Like
1Likes
Like

Posted 27 November 2012 - 12:46 PM

I really can't recommend against

system("pause");
enough. Especially when you can have highly portable functions available to you in the standard library.

I prefer to use something like:
void pause_console(char const* message)
{
   std::cout << message << std::flush;
   std::cin.ignore(std::numeric_limits< std::streamsize >::max(), '\n');
}

Benefits? Independent of IDE in use and is platform independent.

Incidentally, the MSVC compiler in VS2012 is perfectly fine. I would recommend sticking with it on the Windows platform. In fact, the only reason I use g++ on Windows is to experiment with variadic templates among other things that VS doesn't yet support. For the simple stuff, though, don't sweat over compiler differences too much. Your results should be the same regardless.


FYI, Microsoft released CTP about a month ago (http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx) that supports variadic templates and few more nice features of C++11. They haven't yet updated Intellisense so its a bit weird because you will get syntax error in some places but it will compile. I used it in my main project for a while and didn't encounter any errors.

It can be downloaded from here: http://www.microsoft.com/en-us/download/details.aspx?id=35515

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon :)

#16 brx   Members   -  Reputation: 695

Like
0Likes
Like

Posted 27 November 2012 - 03:18 PM

that supports variadic templates and few more nice features of C++11.


Wow, thanks for that info! I just installed the first service pack for VS2012, but I didn't see anything about variadic templates in the description - but then again, that was probably because I stopped reading after "enable C++ applications to target Windows XP from Visual Studio 2012". I was so waiting for this. Now I can finally say that there is no reason left to finally ditch the very outdated VS2008 and move to VS2012.

I just went back and read through the MSDN blocks, but none of them said anything about upgrades to the compiler... So I guess I just have to try it ;) Thanks again for the info

#17 noizex   Members   -  Reputation: 854

Like
0Likes
Like

Posted 27 November 2012 - 05:15 PM


that supports variadic templates and few more nice features of C++11.


Wow, thanks for that info! I just installed the first service pack for VS2012, but I didn't see anything about variadic templates in the description - but then again, that was probably because I stopped reading after "enable C++ applications to target Windows XP from Visual Studio 2012". I was so waiting for this. Now I can finally say that there is no reason left to finally ditch the very outdated VS2008 and move to VS2012.

I just went back and read through the MSDN blocks, but none of them said anything about upgrades to the compiler... So I guess I just have to try it ;) Thanks again for the info


Its CTP so its a preview of new features that haven't yet been incorporated into main MSVC compiler. You will have to switch compiler in project options to use it. Its supposed to not be used for real purposes until they release the real version, but I used it in my project without problems, as I mentioned already.

#18 SiCrane   Moderators   -  Reputation: 9501

Like
1Likes
Like

Posted 27 November 2012 - 05:25 PM

The official Update 1 was just released yesterday. It's not a preview anymore.

#19 Radikalizm   Crossbones+   -  Reputation: 2805

Like
0Likes
Like

Posted 27 November 2012 - 06:15 PM

The official Update 1 was just released yesterday. It's not a preview anymore.


This update does not contain the features from the november CTP though :(

I gets all your texture budgets!


#20 BigDaveDev   Members   -  Reputation: 131

Like
0Likes
Like

Posted 28 November 2012 - 04:01 AM


-snip -


FYI, Microsoft released CTP about a month ago (http://blogs.msdn.co...uture-of-c.aspx) that supports variadic templates and few more nice features of C++11. They haven't yet updated Intellisense so its a bit weird because you will get syntax error in some places but it will compile. I used it in my main project for a while and didn't encounter any errors.

It can be downloaded from here: http://www.microsoft...s.aspx?id=35515

I'm not sure when these changes will be incorporated into main version but lets hope it will be soon Posted Image


Thanks! =D

Worth noting, though, that the standard library is NOT updated with this CTP. This means that the following won't work:
std::vector< int > my_ints = {1, 2, 3, 4, 5}; // won't compile

// Neither will this...
for(auto i: {1, 2, 3, 4, 5})
{
	std::cout << i << ' ';
}

since that relies on library features... Still, getting closer!! At least now I can begin prep-ing my g++4.7 projects for MSVC a little at a time
Cows would last a lot longer if they weren't made of steak and leather.

Check out my site: bigdavedev.com




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS