Microsoft MVP성태의 닷넷 이야기
VS.NET IDE: 192. Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 7052
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드

Visual Studio 2022에서 기본 C/C++ 프로젝트를 생성한 다음,

#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
}

빌드한 결과물을 Windows XP / 2003에서 실행하면 이런 오류가 발생합니다.

C:\temp\xptest.exe is not a valid Win32 application.

이 문제를 해결하려면, XP용으로 빌드하도록 설정해야 하는데요, 이를 위해 우선 Visual Studio 측에 다음의 구성 요소를 설치해야 합니다.

["Tools" / "Get Tools and Features..." 메뉴]

"Individual components" 탭 / "Compilers, build tools, and runtimes" 카테고리 - "C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]" 

이후, C++ 프로젝트 속성창에 들어가 "Properties" / "General" / "Platform Toolset"을 "Visual Studio 2017 - Windows XP (v141_xp)"로 변경하면 됩니다. (참고로, 이렇게 변경하면 Windows SDK Version도 자동으로 "7.0"으로 바뀝니다.)

끝입니다. 이제 빌드하고 다시 실행하면 XP/2003에서도 정상적으로 실행됩니다.




경우에 따라 XP/2003에서 실행 시 이런 오류가 발생할 수 있습니다.

xptest.exe - Unable To Locate Component

This application has failed to start because MSVCP140.dll was not found. Re-installing the application may fix this problem. 

전에 한 번 언급했지만, 이것은 재배포 런타임("Microsoft Visual C++ 2015 Redistributable Update 3")을 설치하면 됩니다.

VCRUNTIME140.dll, MSVCP140.dll, VCRUNTIME140.dll, VCRUNTIME140_1.dll이 없어 exe 실행이 안 되는 경우
; https://www.sysnet.pe.kr/2/0/12714




위와 같은 문제를 겪지 않기 위해, "MSVCP140.dll" 의존성을 갖지 않도록 C/C++ / "Code Generation" 범주의 "Runtime Library" 값을 "Multi-threaded (/MT)"로 설정할 수 있습니다.

재미있는 건, 이렇게 설정한 프로젝트를 Visual Studio 2022에서 빌드하면 문제가 없는데, 2019에서 빌드하면 XP/200에서 실행 시 이런 오류가 발생합니다.

xptest.exe - Entry Point Not Found

The procedure entry point InitializeCriticalSectionEx could not be located in the dynamic link library KERNEL32.dll. 

이것 역시 전에 언급한 것처럼, CRT 라이브러리가 더 이상 XP/2003을 지원하지 않으면서 발생한 변화였는데요, 웬일인지 동일한 프로젝트를 Visual Studio 2019에서 빌드하면 InitializeCriticalSectionEx를 사용하는 PE 파일을 생성하게 됩니다.

// Visual Studio 2019 + /MT 옵션으로 빌드한 경우,

c:\temp> dumpbin /IMPORTS xptest.exe
Microsoft (R) COFF/PE Dumper Version 14.41.34120.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file xptest.exe

File Type: EXECUTABLE IMAGE

  Section contains the following imports:

    KERNEL32.dll
                41A000 Import Address Table
                426230 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                   EA EncodePointer
                   CA DecodePointer
                   EE EnterCriticalSection
                  339 LeaveCriticalSection
                  2E4 InitializeCriticalSectionEx
                   D1 DeleteCriticalSection
                  367 MultiByteToWideChar
                  511 WideCharToMultiByte
                  32C LCMapStringEx
                // ...[생략]...

반면, Visual Studio 2022에서 동일한 프로젝트를 빌드하면 InitializeCriticalSectionEx를 사용하지 않는 PE 파일을 생성합니다.

// Visual Studio 2022 + /MT 옵션으로 빌드한 경우, 
// (아마도 Visual Studio 2022용 빌드 도구에서도 가능하긴 할 것입니다.)

c:\temp> dumpbin /IMPORTS xptest.exe
Microsoft (R) COFF/PE Dumper Version 14.41.34120.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file xptest.exe

File Type: EXECUTABLE IMAGE

  Section contains the following imports:

    KERNEL32.dll
                41B000 Import Address Table
                429408 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                  202 GetLastError
                  511 WideCharToMultiByte
                  473 SetLastError
                  2E3 InitializeCriticalSectionAndSpinCount
                  4BC SwitchToThread
                  4C5 TlsAlloc
                  4C7 TlsGetValue
                  4C8 TlsSetValue
                  4C6 TlsFree
                // ...[생략]...

따라서 만약 2019 버전으로 빌드해야 한다면 반드시 "Multi-threaded DLL (/MD)" 옵션으로 빌드해야 합니다.

(그렇긴 한데, 설마 요즘에도 XP/2003을 쓰고 있는 환경은 없겠죠? ^^;)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/26/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
13011정성태3/21/202215913오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
13010정성태3/21/202212653오류 유형: 801. Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
13009정성태3/20/202215245개발 환경 구성: 640. docker - ibmcom/db2 컨테이너 실행
13008정성태3/19/202214821VS.NET IDE: 176. 비주얼 스튜디오 - 솔루션 탐색기에서 프로젝트를 선택할 때 csproj 파일이 열리지 않도록 만드는 방법
13007정성태3/18/202213233.NET Framework: 1181. C# - Oracle.ManagedDataAccess의 Pool 및 그것의 연결 개체 수를 알아내는 방법파일 다운로드1
13006정성태3/17/202215649.NET Framework: 1180. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 remuxing.c 예제 포팅
13005정성태3/17/202213910오류 유형: 800. C# - System.InvalidOperationException: Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.
13004정성태3/16/202213438디버깅 기술: 182. windbg - 닷넷 메모리 덤프에서 AppDomain에 걸친 정적(static) 필드 값을 조사하는 방법
13003정성태3/15/202213752.NET Framework: 1179. C# - (.NET Framework를 위한) Oracle.ManagedDataAccess 패키지의 성능 카운터 설정 방법
13002정성태3/14/202215359.NET Framework: 1178. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 http_multiclient.c 예제 포팅
13001정성태3/13/202215936.NET Framework: 1177. C# - 닷넷에서 허용하는 메서드의 매개변수와 호출 인자의 최대 수
13000정성태3/12/202214910.NET Framework: 1176. C# - Oracle.ManagedDataAccess.Core의 성능 카운터 설정 방법
12999정성태3/10/202214740.NET Framework: 1175. Visual Studio - 프로젝트 또는 솔루션의 Clean 작업 시 응용 프로그램에서 생성한 파일을 함께 삭제파일 다운로드1
12998정성태3/10/202213159.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
12997정성태3/10/202222242오류 유형: 799. Oracle.ManagedDataAccess - "ORA-01882: timezone region not found" 오류가 발생하는 이유
12996정성태3/9/202223708VS.NET IDE: 175. Visual Studio - 인텔리센스에서 오버로드 메서드를 키보드로 선택하는 방법
12995정성태3/8/202216083.NET Framework: 1173. .NET에서 Producer/Consumer를 구현한 BlockingCollection<T>
12994정성태3/8/202215152오류 유형: 798. WinDbg - Failed to load data access module, 0x80004002
12993정성태3/4/202214844.NET Framework: 1172. .NET에서 Producer/Consumer를 구현하는 기초 인터페이스 - IProducerConsumerCollection<T>
12992정성태3/3/202217803.NET Framework: 1171. C# - BouncyCastle을 사용한 암호화/복호화 예제파일 다운로드1
12991정성태3/2/202215600.NET Framework: 1170. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 transcode_aac.c 예제 포팅
12990정성태3/2/202215715오류 유형: 797. msbuild - The BaseOutputPath/OutputPath property is not set for project '[...].vcxproj'
12989정성태3/2/202213722오류 유형: 796. mstest.exe - System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.Tips.WebLoadTest.Tip
12988정성태3/2/202212154오류 유형: 795. CI 환경에서 Docker build 시 csproj의 Link 파일에 대한 빌드 오류
12987정성태3/1/202214408.NET Framework: 1169. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 demuxing_decoding.c 예제 포팅
12986정성태2/28/202216382.NET Framework: 1168. C# -IIncrementalGenerator를 적용한 Version 2 Source Generator 실습 [1]
... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...