Microsoft Visual Studio 2010 Compile for MIPS - c++

I am trying to figure out how to compile a simple hello world in Visual Studio, but for MIPS processor. Followed the guideline posted on MS website. Only difference is I am trying this on Visual Studio 2010:
#include <iostream>
int main()
{
std::cout << "This is a native C++ program." << std::endl;
return 0;
}
Tried compiling with the /QMR4100 options:
c:\Users\ukhan\Documents\Auto_Security\Test_Code>cl /QMR4100 /EHsc forloop.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
**cl : Command line warning D9002 : ignoring unknown option '/QMR4100'**
forloop.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:forloop.exe
forloop.obj
So, I checked help for options and it does seem the command line option is not valid:
c:\Users\ukhan\Documents\Auto_Security\Test_Code>cl /?
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
C/C++ COMPILER OPTIONS
-OPTIMIZATION-
/O1 minimize space /O2 maximize speed
/Ob<n> inline expansion (default n=0) /Od disable optimizations (default)
/Og enable global optimization /Oi[-] enable intrinsic functions
/Os favor code space /Ot favor code speed
/Ox maximum optimizations
/favor:<blend|AMD64|INTEL64> select processor to optimize for, one of:
blend - a combination of optimizations for several different x64 processors
AMD64 - 64-bit AMD processors
INTEL64 - Intel(R)64 architecture processors
-CODE GENERATION-
/GF enable read-only string pooling /Gm[-] enable minimal rebuild
/Gy[-] separate functions for linker /GS[-] enable security checks
/GR[-] enable C++ RTTI /GX[-] enable C++ EH (same as /EHsc)
/EHs enable C++ EH (no SEH exceptions) /EHa enable C++ EH (w/ SEH exceptions)
/EHc extern "C" defaults to nothrow
/fp:<except[-]|fast|precise|strict> choose floating-point model:
except[-] - consider floating-point exceptions when generating code
fast - "fast" floating-point model; results are less predictable
precise - "precise" floating-point model; results are predictable
strict - "strict" floating-point model (implies /fp:except)
/Qfast_transcendentals generate inline FP intrinsics even with /fp:except
/GL[-] enable link-time code generation /GA optimize for Windows Application
/Ge force stack checking for all funcs /Gs[num] control stack checking calls
/Gh enable _penter function call /GH enable _pexit function call
/GT generate fiber-safe TLS accesses /RTC1 Enable fast checks (/RTCsu)
/RTCc Convert to smaller type checks /RTCs Stack Frame runtime checking
/RTCu Uninitialized local usage checks
/clr[:option] compile for common language runtime, where option is:
pure - produce IL-only output file (no native executable code)
safe - produce IL-only verifiable output file
oldSyntax - accept the Managed Extensions syntax from Visual C++ 2002/2003
initialAppDomain - enable initial AppDomain behavior of Visual C++ 2002
noAssembly - do not produce an assembly
/homeparams Force parameters passed in registers to be written to the stack
/GZ Enable stack checks (/RTCs)
/arch:AVX enable use of Intel(R) Advanced Vector Extensions instructions
-OUTPUT FILES-
/Fa[file] name assembly listing file /FA[scu] configure assembly listing
/Fd[file] name .PDB file /Fe<file> name executable file
/Fm[file] name map file /Fo<file> name object file
/Fp<file> name precompiled header file /Fr[file] name source browser file
/FR[file] name extended .SBR file /Fi[file] name preprocessed file
/doc[file] process XML documentation comments and optionally name the .xdc file
-PREPROCESSOR-
/AI<dir> add to assembly search path /FU<file> forced using assembly/module
/C don't strip comments /D<name>{=|#}<text> define macro
/E preprocess to stdout /EP preprocess to stdout, no #line
/P preprocess to file /Fx merge injected code to file
/FI<file> name forced include file /U<name> remove predefined macro
/u remove all predefined macros /I<dir> add to include search path
/X ignore "standard places"
-LANGUAGE-
/Zi enable debugging information /Z7 enable old-style debug info
/Zp[n] pack structs on n-byte boundary /Za disable extensions
/Ze enable extensions (default) /Zl omit default library name in .OBJ
/Zg generate function prototypes /Zs syntax check only
/vd{0|1|2} disable/enable vtordisp /vm<x> type of pointers to members
/Zc:arg1[,arg2] C++ language conformance, where arguments can be:
forScope[-] - enforce Standard C++ for scoping rules
wchar_t[-] - wchar_t is the native type, not a typedef
auto[-] - enforce the new Standard C++ meaning for auto
trigraphs[-] - enable trigraphs (off by default)
/openmp enable OpenMP 2.0 language extensions
-MISCELLANEOUS-
#<file> options response file /?, /help print this help message
/bigobj generate extended object format /c compile only, no link
/errorReport:option Report internal compiler errors to Microsoft
none - do not send report
(press <return> to continue)
prompt - prompt to immediately send report
queue - at next admin logon, prompt to send report (default)
send - send report automatically
/FC use full pathnames in diagnostics /H<num> max external name length
/J default char type is unsigned
/MP[n] use up to 'n' processes for compilation
/nologo suppress copyright message /showIncludes show include file names
/Tc<source file> compile file as .c /Tp<source file> compile file as .cpp
/TC compile all files as .c /TP compile all files as .cpp
/V<string> set version string /w disable all warnings
/wd<n> disable warning n /we<n> treat warning n as an error
/wo<n> issue warning n once /w<l><n> set warning level 1-4 for n
/W<n> set warning level (default n=1) /Wall enable all warnings
/WL enable one line diagnostics /WX treat warnings as errors
/Yc[file] create .PCH file /Yd put debug info in every .OBJ
/Yl[sym] inject .PCH ref for debug lib /Yu[file] use .PCH file
/Y- disable all PCH options /Zm<n> max memory alloc (% of default)
/Wp64 enable 64 bit porting warnings
-LINKING-
/LD Create .DLL /LDd Create .DLL debug library
/LN Create a .netmodule /F<num> set stack size
/link [linker options and libraries] /MD link with MSVCRT.LIB
/MT link with LIBCMT.LIB /MDd link with MSVCRTD.LIB debug lib
/MTd link with LIBCMTD.LIB debug lib
c:\Users\ukhan\Documents\Auto_Security\Test_Code>
Basically I am trying to generate assembly code for MIPS R4000 from Microsoft Visual C++. Any help is appreciated.

There used to be a build of the desktop version of Windows that ran on MIPS, it was discontinued in 2000 due to lack of use. Much the same happened to the mobile version, struck by an apple in 2010. Accordingly, the compiler support was discontinued as well, you need VS2008 or less.
The cross compiler in VS2008 is present in c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\bin\x86_mips. A snip from the options displayed with /?:
/QMmips2 MIPS II ISA (default) /QMmips3 MIPS III ISA
/QMmips4 MIPS IV ISA /QMmips5 MIPS V ISA
/QMmips16 MIPS 16 ASE /QMmips32 MIPS 32 ISA
/QMmips64 MIPS 64 ISA
/QMn32[-] generate code for MIPS n32 mode
/QMR3900 optimize for r3900 /QMR4100 optimize for r4100
/QMR4200 optimize for r4200 /QMR4300 optimize for r4300
/QMR5400 optimize for r5400 /QMVIPER optimize for Viper
/QMRFWCE generic WinCE -QMFPE- MIPS /QMRWCE generic WinCE MIPS (Default)
/QMFPE[-] use floating point emulation /QMase3D use MIPS-3D ASE
VS2008 is still available through a reseller like Amazon, is free with an MSDN subscription or can be obtained through an auction site like Ebay. The Professional edition is required to get mobile support.

Related

VS2015 supports magic statics, so why this warning?

I'm upgrading from VS2013 to VS2015 and am getting the following warning. I thought VS2015 implemented magic statics so that the local static object should be thread-safe, so what is going on?
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(698): error C2220: warning treated as error - no 'object' file generated
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(704): note: see reference to function template instantiation '_Ty &std::_Immortalize<std::_Generic_error_category>(void)' being compiled
with
[
_Ty=std::_Generic_error_category
]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\system_error(698): warning C4640: '_Static': construction of local static object is not thread-safe
The error is in the system_error header from the VS installation folder. The error is in this function:
template<class _Ty> inline
_Ty& _Immortalize()
{ // return a reference to an object that will live forever
static _Immortalizer<_Ty> _Static;
return (*reinterpret_cast<_Ty *>(&_Static._Storage));
}
That's all the context there is in the error, and I can't see where system_error actually gets included.
Compiler flags are:
/Yu"stdafx.h" /GS /analyze /W3 /wd"4481" /wd"4251" /Zc:wchar_t
/Zi /Gm- /O2 /sdl /Fd"x64\Release\\Release_vc140.pdb" /Zc:inline /fp:precise
/errorReport:prompt /WX /Zc:forScope /Gd /MT /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\MyProj.pch"
Update
Sorry, it seems fixed now. It looks like I was on the v140_xp toolset and wrong TargetPlatformVersion. This one must have slipped through the net when I thought I'd replaced them all. I'm not quite sure why getting those wrong would result in this error though. Anyway, thanks for the help so far.
It looks like its caused by the bogus warning which is turned into an Error, read this connect bug:
https://connect.microsoft.com/VisualStudio/feedback/details/2539759/c4640-warning-cannot-be-disabled
The error C2220 indicates you have enables /WX switch, which tells the compiler to treat all warnings as errors.
you can turn this warning off with:
#pragma warning (disable : 4640)
btw. unrelated, but might be usefull to You. You use _Immortalizer as a name for your class which starts with underscore followed by uppercase latter. This is prohibited by standard: read here: What are the rules about using an underscore in a C++ identifier?.
It's caused by changes in MSBuild's toolset v140_xp. Issue appears when:
project builds with VS2015 Update 2, toolset v140_xp
project configuration is Dynamic Library
project was created with ATL App Wizard, so *.vcxproj contains tag <Keyword>AtlProj</Keyword>
There is workaround: open *.vcxproj file, find tag <Keyword>AtlProj</Keyword> and replace it with <Keyword>Win32Proj</Keyword>. Nothing will be changed while compiling, but warning will disappear.
If you want to know details, navigate to the directory C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp, open Toolset.props and find comment <!-- Added /Zc:threadSafeInit- for ATL dll projects and enable the C4640 warnning -->. The line below it enables warning and disables "magic static" feature from C++11.
P.S. Please note that warning isn't useless: 'magic static' uses thread-local storage which suffers from ugly WindowsXP kernel bug: access to TLS from DLL causes crash when application built without TLS support. Any DLL plugins with WinXP support affected by this bug.

Embed a string of compiler options in an executable (Visual Studio)

Using gcc and Makefiles, I am able to embed some compiler options into a string for an executable to access as follows:
Makefile:
CXX=/usr/bin/g++
CXXFLAGS=-ansi -Wall -c
CXXDEFINES='-DCXXCOMMAND="$(CXX) $(CXXFLAGS)"'
C++ file:
#ifdef CXXCOMMAND
std::cout << "C++ Command: " << CXXCOMMAND << std::endl;
#endif
And then I am able to print it to the console from the executable.
Is it possible to do this in Visual Studio? Specifically I am looking to put in the optimization flags (/O2, /Od, etc...), but the more I have access to, the better things will work for me.
Microsoft Visual Studio Professional 2012
Intel C++ Composer XE 2013 SP1
Yes, sort of. You can define a macro in the project properties that contains a string, and embed within it any project property values you want. However, these properties, while used to construct the command line, are not the actual command line flags themselves.
For example, add the following as a Preprocessor Definition in the C/C++ Preprocessor project properties:
CXXCOMMAND="%(Optimization)"
Then CXXCOMMAND is "MinSpace" for a build set to compile with /O1.
Just be careful to have only an even number of quotes in your preprocessor define...

How do you run cl.exe from cmd using the same settings as in MSVS?

I have a c++ project in MSVS 2010 Express. I have been planning to write several unit tests to validate this project. Right now they go along the following lines:
#include "header.h" //Header is the header for the source I want to test
void testSomeFunction()
{
//Call function (from external src, prototype in header.h)
//Save output to file
}
int main()
{
testSomeFunction();
return 0;
}
I am creating these source files outside my project because I want to be able to run each of them as individual executable, but I am having trouble getting the Microsoft linker to link them.
This is my problem so far (CMD output):
cl ut_Converter.cpp Converter.obj
ut_Converter.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:ut_Converter.exe
ut_Converter.obj
Converter.obj
Converter.obj : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in ut_Converter.obj
Converter.obj : fatal error LNK1313: pure module detected; cannot link with ijw/native modules
I never really use Microsoft products, I'm familiar with using the GNU tools GCC and make but I have to use the Microsoft tools for this and I have no idea how they work.
Maybe I'm going about building these tests the stupid way but it's the best way I can think of right now.
This is what I want to do:
Compile the source files in my project into object files
Compile my test files into object files
Link the test object file with the appropriate project object files to produce the test executable
How do I go about doing that? (I'm guessing there are some settings I need to set to make everything compatible but I have no idea what they are or how I would go about setting them)
Extra: I know it mentions the debug level but I'd be willing to bet that there will be other incompatible settings. Is there a way to find out what the settings are in the program so I can pass them to cl.exe when I run it?
Edit: When I say command prompt I do mean the one that comes with Visual Studio with all the environment variables setup.
Have you tried going to Programs / Microsoft Visual ... / ... Tools / ... Command Prompt, and running from that dos console window which has the environment variables setup?

Visual Studio Compiler Default for /O

Does VS2010/12's compiler use a default optimization level when none of /Od,/O1,/O2,/Ox is provided in a C++ compilation command line?
I'm currently using /Od since I witnessed some optimization related bugs when using the other levels. However, this leads to /GS being disabled - which is unwanted.
When I clear the box for the "Project Properties->C/C++->Optimization->Optimization" option, I see the command line indeed doesn't contain any option. But I don't know if this just means the compiler uses some default optimization level.
No optimization seems to be the default - see output from "cl /?" below:
-OPTIMIZATION-
/O1 minimize space /O2 maximize speed
/Ob<n> inline expansion (default n=0) /Od disable optimizations (default)
/Og enable global optimization /Oi[-] enable intrinsic functions
/Os favor code space /Ot favor code speed
/Ox maximum optimizations /Oy[-] enable frame pointer omission

Gen code without runtime checks in VC++

How do I generate pure code (without runtime checks) in VC++ 2010 Express ? For example I removed Buffer Security Check ( set compile opt /GS-), but in my code I again saw these calls
call __security_init_cookie
...
call _RTC_CheckEsp
...
call _RTC_CheckEsp
...
How do I remove these calls?
The MSVC docs indicate that __security_init_cookie is called by the CRT runtime for "code compiled with /GS (Buffer Security Check) and in code that uses exception handling" (emphasis added). See http://msdn.microsoft.com/en-us/library/ms235362%28v=VS.100%29.aspx
I wouldn't be surprised if there's code in the runtime library itself that depends on the security cookie having been initialized, whether your code uses it or not (in other words, the runtime library code may have been compiled with /GS, and if so, it needs the cookie initialized whether or not your code does).
As for the _RTC_CheckEsp call - that should be controlled by the /RTCs or the /RTC1 option. Remove those options from your build and there should be no calls to _RTC_CheckEsp.
Disable /RTC compiler switch
http://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx