We recommend using Visual Studio 2017

Compiler Error C2341


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C2341.

section name' : segment must be defined using #pragma data_seg, code_seg or section prior to use

An allocate statement refers to a segment not yet defined by code_seg, data_seg, or section pragmas.

The following sample generates C2341:

// C2341.cpp  
// compile with: /c  
__declspec(allocate(".test"))   // C2341  
int j = 1;  

Possible resolution:

// C2341b.cpp  
// compile with: /c  
#pragma data_seg(".test")  
int j = 1;