E.Meir
E.Meir

Reputation: 2216

VisualStudio- Custom platform

I have a situation that i need my app to support a 3'rd option of platform.

X86 & X64 are already being used, so what i am looking after is to add a new custom platform, when i choose that platform- the dll files will change accordingly.

My goal is to add a new condition to the project file, something like that:

 <Reference Include="newCustomPlatform" Condition="'$(Platform)'=='newCustomPlatform'">
      <HintPath>..\..\_libBinary\87\newCustomPlatform.dll</HintPath>
    </Reference>

I looked for an answer for that but i only found x86 or x64 related answers.

Can it be done?

Upvotes: 0

Views: 343

Answers (1)

Cody Gray
Cody Gray

Reputation: 244682

Visual Studio doesn't support arbitrary custom platforms. It only supports a defined set of supported target platforms. In general common use, these are x86 (IA-32) and x86-64 (AMD64). If you have the necessary build tools installed, you may also get Itanium or ARM support. Historical versions have supported Alpha and PowerPC, and perhaps a few other architectures that I'm forgetting.

None of this helps you, of course. If you ultimately want to produce a 32-bit x86 or 64-bit x86 binary, you absolutely must use one of those two platforms.

What you'll want to do instead is to create new configurations. By default, you get "Debug" and "Release" for each target platform, but you can have as many or as few configurations as you want. What I do is create "Debug (Custom)" and "Release (Custom)" (or any name you want) with the necessary custom attributes.

Aside from that, maybe I'm reading too much into your example, but does 87 suggest that you are trying to create a platform that limits itself to the x87 instruction set, without using SSE or newer instruction sets? If so, that's configurable with the /arch compiler switch. /arch:IA32 limits you to the x87 instruction set; /arch:SSE2 is the default, and does just what it says. Other options include /arch:SSE, /arch:AVX, and /arch:AVX2. These options affect the definitions of some pre-defined macros. If AVX is supported, __AVX__ will be defined. If AVX2 is supported, __AVX2__ will be defined. Otherwise, you'll need to check the value of the _M_IX86_FP symbol: it will be 0 if /arch:IA32 is used, 1 if /arch:SSE is used, or 2 for /arch:SSE2 and later. You can test the values of these symbols and conditionally point the linker to the necessary libraries; something like:

#if (defined _M_IX86)
    #if (defined __AVX2__)
       #pragma comment(lib, "bin\avx2\MyData.lib")
    #elif (defined __AVX__)
       #pragma comment(lib, "bin\avx\MyData.lib")
    #elif (_M_IX86_FP == 2)
       #pragma comment(lib, "bin\sse2\MyData.lib")
    #elif (_M_IX86_FP == 1)
       #pragma comment(lib, "bin\sse\MyData.lib")
    #else
       #pragma comment(lib, "bin\87\MyData.lib")
#endif

Upvotes: 1

Related Questions