Microsoft MVP성태의 닷넷 이야기
VS.NET IDE: 192. Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 7039
글쓴 사람
정성태 (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)
13036정성태4/24/202215169.NET Framework: 1997. C# - nano 시간을 가져오는 방법 [2]
13035정성태4/22/202216426Windows: 204. Windows 10부터 바뀐 QueryPerformanceFrequency, QueryPerformanceCounter
13034정성태4/21/202214004.NET Framework: 1996. C# XingAPI - 주식 종목에 따른 PBR, PER, ROE, ROA 구하는 방법(t3320, t8430 예제)파일 다운로드1
13033정성태4/18/202215119.NET Framework: 1195. C# - Thread.Yield와 Thread.Sleep(0)의 차이점(?)
13032정성태4/17/202215315오류 유형: 805. Github의 50MB 파일 크기 제한 - warning: GH001: Large files detected. You may want to try Git Large File Storage
13031정성태4/15/202214986.NET Framework: 1194. C# - IdealProcessor와 ProcessorAffinity의 차이점
13030정성태4/15/202213535오류 유형: 804. 정규 표현식 오류 - Quantifier {x,y} following nothing.
13029정성태4/14/202214936Windows: 203. iisreset 후에도 이전에 설정한 전역 환경 변수가 w3wp.exe에 적용되는 문제
13028정성태4/13/202215024.NET Framework: 1193. (appsettings.json처럼) web.config의 Debug/Release에 따른 설정 적용
13027정성태4/12/202214909.NET Framework: 1192. C# - 환경 변수의 변화를 알리는 WM_SETTINGCHANGE Win32 메시지 사용법파일 다운로드1
13026정성태4/11/202216300.NET Framework: 1191. C 언어로 작성된 FFmpeg Examples의 C# 포팅 전체 소스 코드 [3]
13025정성태4/11/202215556.NET Framework: 1190. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 vaapi_encode.c, vaapi_transcode.c 예제 포팅
13024정성태4/7/202213793.NET Framework: 1189. C# - 런타임 환경에 따라 달라진 AppDomain.GetCurrentThreadId 메서드
13023정성태4/6/202214387.NET Framework: 1188. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 transcoding.c 예제 포팅 [3]
13022정성태3/31/202213953Windows: 202. 윈도우 11 업그레이드 - "PC Health Check"를 통과했지만 여전히 업그레이드가 안 되는 경우 해결책
13021정성태3/31/202215767Windows: 201. Windows - INF 파일을 이용한 장치 제거 방법
13020정성태3/30/202214000.NET Framework: 1187. RDP 접속 시 WPF UserControl의 Unloaded 이벤트 발생파일 다운로드1
13019정성태3/30/202214474.NET Framework: 1186. Win32 Message를 Code로부터 메시지 이름 자체를 텍스트로 구하고 싶다면?파일 다운로드1
13018정성태3/29/202215220.NET Framework: 1185. C# - Unsafe.AsPointer가 반환한 포인터는 pinning 상태일까요? [5]
13017정성태3/28/202214193.NET Framework: 1184. C# - GC Heap에 위치한 참조 개체의 주소를 알아내는 방법 - 두 번째 이야기 [3]
13016정성태3/27/202215835.NET Framework: 1183. C# 11에 추가된 ref 필드의 (우회) 구현 방법파일 다운로드1
13015정성태3/26/202217528.NET Framework: 1182. C# 11 - ref struct에 ref 필드를 허용 [1]
13014정성태3/23/202214995VC++: 155. CComPtr/CComQIPtr과 Conformance mode 옵션의 충돌 [1]
13013정성태3/22/202212773개발 환경 구성: 641. WSL 우분투 인스턴스에 파이썬 2.7 개발 환경 구성하는 방법
13012정성태3/21/202212428오류 유형: 803. C# - Local '...' or its members cannot have their address taken and be used inside an anonymous method or lambda expression
13011정성태3/21/202215913오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
... 31  32  33  34  35  [36]  37  38  39  40  41  42  43  44  45  ...