I'm taking a MOOC course on data structures and algorithm. I would like to use c++, and I need to set my compiler options to the following
g++ -pipe -O2 -std=c++14 -lm
I'm currently using MS Visual Studio 2017 on Windows. Is it even possible? Do I need to do custom build? The following is the paragraph taken from the MOOC mentions about Windows users having to use Cygwin, but I have no clue what that means. Can anybody shed some light on a feasible way to do this?
Your solution will be compiled as follows. We recommend that when
testing your solution locally, you use the same compiler flags for
compiling. This will increase the chances that your program behaves in
the same way on your machine and on the testing machine (note that a
buggy program may behave differently when compiled by different
compilers, or even by the same compiler with different flags).
C++ (g++ 5.2.1). File extensions: .cc, .cpp. Flags
g++ -pipe -O2 -std=c++14 -lm
If your C/C++ compiler does not recognize the "-std=c++14" flag, try
replacing it with "-std=c++11" or "-std=c++0x" flag or compiling
without this flag at all (all starter solutions can be compiled
without it). On Linux and MacOS, you probably have the required
compiler. On Windows, you may use your favorite compiler or install an
environment such as cygwin.
As they said you should choose cygwin (https://cygwin.com/install.html).
These would be the flags for msvc: /std:c++14 /O2 /Im
You can set compiler options for each project in its Property Pages
dialog box. In the left pane, select Configuration Properties, C/C++
and then choose the compiler option category.
For the categories lookup: https://learn.microsoft.com/de-de/cpp/build/reference/compiler-options-listed-by-category
Related
I'm writing some code that requires to have C++11 support for my Code::Blocks 12.11. I am using default GNU GCC Compiler came with MingW. Is there any way I can do this?
Go to Toolbar -> Settings -> Compiler
In the Selected compiler drop-down menu, make sure GNU GCC Compiler is selected
Below that, select the compiler settings tab and then the compiler flags tab underneath
In the list below, make sure the box for "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]" is checked
Click OK to save
The answer with screenshots (put the checkbox as in the second pic, then press OK):
A simple way is to write:
-std=c++11
in the Other Options section of the compiler flags. You could do this on a per-project basis (Project -> Build Options), and/or set it as a default option in the Settings -> Compilers part.
Some projects may require -std=gnu++11 which is like C++11 but has some GNU extensions enabled.
If using g++ 4.9, you can use -std=c++14 or -std=gnu++14.
Use g++ -std=c++11 -o <output_file_name> <file_to_be_compiled>
I am taking a class and one the expectations are that the source code we submit will compile on our professors computer. Seems reasonable. I really do not want to install windows or use visualization. One of my classmates posted that the code below will do the trick. Any thoughts on this? Can it be improved to be closer to a strict ANSI/ISO c++ compile?
$ g++ -std=c++98 -Wall -Wextra -Werror main.cpp -o outputprogram
My OS is 10.8.x
g++ is:
i686-apple-darwin11-llvm-g++-4.2
And gcc is
i686-apple-darwin11-llvm-gcc-4.2:
How should I compile source code in c++ on a mac to ensure it will compile correctly in Windows Visual Studio Complier while adhering to ANSI/ISO
You really can't do that. Not possible. Compilers behave slightly differently in different places and sometimes that leads to compilation failures and/or slightly different program behavior. When it comes to Microsoft Compiler, it can happily compile code that baffles G++(typically templates), and vice versa, and that's even if you don't take into account non-standard function and extensions. So, the only sure way to test compiler is to use that compiler.
Issues I personally run into when developing code that is supposed to work with g++/cl.exe (cl.exe == microsoft compiler).
Compared to cl.exe, g++ is insanely slow, at least on windows. (2..5x times slower)
g++ sometimes can't compile template constructs cl.exe processes just fine.
cl.exe cannot process insanely large string constants (compared to g++).
cl.exe (VS2008 express) cannot detect UTF8 encoding without a BOM.
Mixing encodings with cl.exe (when OS uses encoding A, source file is in encoing B, and you want to display wchar_t string using function that requires encoidng C) is a nightmare.
C standard library functions are different on cl.exe/g++. One compiler can have a function that isn't present on another compiler (some of them don't have some string *ncmp function), compiler might have non-standard functions that isn't present in another compiler (strcpy_s), and certain functions might behave differently with certain arguments (sprintf with "%S")
passing -Wall to cl.exe produces thousands of warnings for harmless code if windows.h is included. Those warnings cannot be fixed.
There were probably more, but that's what I can remember at the moment.
I really do not want to install windows
You could try using Wine to install Microsoft Compiler onto MacOS. I would expect that you won't be able to install Visual Studio IDE using wine (your mileage may wary), but you should be able to run command line-only microsoft compiler that is shipped with Windows Driver Kit. To use compiler this way you must be really familiar with it, though, so installing windows into virtual machine will be probably much easier.
I am fairly new to C++ programming and very new to programming using the Maya C++ API. I have been trying to use the GNU C++ compiler because I have the 64-bit version of Maya, but I only have the free to use 32-bit version of Visual C++. This is all running in 64-bit Windows Vista.
The problem is when I try to compile the helloWorldCmd.cpp example which comes with Maya I get errors saying there are problems with the Maya header files that are included. Are there actually problems with Maya's compiler headers, or is it just that GNU C++ cannot be used for compiling plugins for Maya? I need help because this issue may stop me dead on going further with learning how to write plug-ins for Maya.
Below are the generated compiler errors. If anyone can decipher what the issue might be I would be most grateful:
C:\MyPrograms>c++ helloWorldCmd.cpp -o helloWorld.exe
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/
maya/MString.h:47:0, from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/
maya/MSimple.h:48, from helloWorldCmd.cpp:30:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/maya/MTypes.h:239:8: e
rror: expected identifier before 'false'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/maya/MTypes.h:239:8: e
rror: expected '}' before 'false'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/maya/MTypes.h:239:8: e
rror: expected unqualified-id before 'false'
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/maya/MTypes.h:239:18:
error: expected declaration before '}' token
In windows you should consider using visual studio to compile maya plugins, in linux g++ the normal procedure is like this and I am not sure how its in windows.
gcc -fmessage-length=0 -Os -pthread -Wno-deprecated -fno-gnu-keywords --fast-math -fPIC -DLINUX -D_USER_=USER -D_HOST_=HOST -D_PROJECTNAME_=PROJECT -D_BUILDVERSION_=VERSION -DNDEBUG -DREQUIRE_IOSTREAM -D_BOOL -I$MAYA_LOCATION/include -I/home/user/customIncludes -O3 -shared -o /tm/helloWorldCmd.so helloWorldCmd.cpp
Please note D_BOOL .
And please not maya not looking for exe, maya looking for mll in windows and so in linux. So if you really new to maya api you should try to use visual studio and maya devkit has a visual studio plugin wizard which will help you configure your plugin and its dependency also.
The problem seems to be that Maya doesn't properly check for the C++ keywords true, false, and the bool type.
After searching on Google, I found a copy of the header file, and if you look through the file yourself you will see that it checks for the macro _BOOL to know if it should make its own bool type.
The solution may be as simple as adding
#define _BOOL
before including the header file.
Note that you may get other errors if the header files checks for other things erroneously.
The problem with using a full version of Visual Studio is that for a learner the cost of buying it is a bit prohibitive and a native install of Visual C++ Express only compiles to 32-bit targets. However, I came across this blog post which explained how to get Software Development Kit to use with Visual C++ Express which does compile to 64-bit. It also explains how to do all further setup ready to build Maya plugins:
http://prilisa.com/2012/01/my-first-maya-2011-c-plug-in.html
Well... When i was searching for a good compiler I came across clang/LLVM. This compiler gives me same result as other compilers like icc, pgi. But the problem is there are very few tutorials on this compiler... Kindly let me know where can I find the tutorials on the clang compiler.
Note by:
I have compiled my c code using the following flags clang -O3 -mfpmath=sse file.c
Clang (the command line compiler) takes gcc-compatible options, but accepts and ignores a lot of flags that GCC takes (like -mfpmath=sse). We aim to generate good code out of the box. There are some flags that allow clang to violate the language standards that can be useful in some scenarios, like -ffast-math though.
If you're looking for good performance, I highly recommend experimenting with link-time-optimization, which allows clang to optimize across source files in your application. Depending on what platform you're on, this is enabled by passing -O4 to the compiler. If you're on linux, you need to use the "gold" linker (see http://llvm.org/docs/GoldPlugin.html). If you're on the mac, it should "just work" with any recent version of Xcode.
The clang is not a compiler, it is just frontend of LLVM compiler. So, when you calls clang, it parses c/c++ file but the optimization and code generation is handled in LLVM itself.
Here you can found a documentation of LLVM optimization and analysis options: http://llvm.org/docs/Passes.html
The full documentation is here http://llvm.org/docs/
Also useful options are listed here http://linux.die.net/man/1/llvmc (I suggest clang will accept most of them too)
I do not understand the documentation for gprof regarding how to compile your program for profiling with gprof. In g++, is it required to compile with the -g option (debugging information) in a addition to the -pg option or not. In each case I get different results, and I would like to see where the bottlenecks in my application are in release mode, not in debug mode, where many optimizations are left out by the compiler (e.g. inlining)
The documentation shows that you can do either, noting that you need -g for line by line profiling. So if you want to profile under release conditions, and can accept not doing line-by-line, you should be able to compile without -g.