Microsoft MVP성태의 닷넷 이야기
VS.NET IDE: 192. Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 7094
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12208정성태4/12/202015942Linux: 29. 리눅스 환경에서 C/C++ 프로그램이 Segmentation fault 에러가 발생한 경우
12207정성태4/2/202015746스크립트: 19. Windows PowerShell의 NonInteractive 모드
12206정성태4/2/202018400오류 유형: 613. 파일 잠금이 바로 안 풀린다면? - The process cannot access the file '...' because it is being used by another process.
12205정성태4/2/202015053스크립트: 18. Powershell에서는 cmd.exe의 명령어를 지원하진 않습니다.
12204정성태4/1/202015062스크립트: 17. Powershell 명령어에 ';' (semi-colon) 문자가 포함된 경우
12203정성태3/18/202017890오류 유형: 612. warning: 'C:\ProgramData/Git/config' has a dubious owner: '...'.
12202정성태3/18/202021158개발 환경 구성: 486. .NET Framework 프로젝트를 위한 GitLab CI/CD Runner 구성
12201정성태3/18/202018388오류 유형: 611. git-credential-manager.exe: Using credentials for username "Personal Access Token". [1]
12200정성태3/18/202018497VS.NET IDE: 145. NuGet + Github 라이브러리 디버깅 관련 옵션 3가지 - "Enable Just My Code" / "Enable Source Link support" / "Suppress JIT optimization on module load (Managed only)"
12199정성태3/17/202016130오류 유형: 610. C# - CodeDomProvider 사용 시 Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '...\f2_6uod0.tmp'.
12198정성태3/17/202019517오류 유형: 609. SQL 서버 접속 시 "Cannot open user default database. Login failed."
12197정성태3/17/202018763VS.NET IDE: 144. .NET Core 콘솔 응용 프로그램을 배포(publish) 시 docker image 자동 생성 - 두 번째 이야기 [1]
12196정성태3/17/202015932오류 유형: 608. The ServicedComponent being invoked is not correctly configured (Use regsvcs to re-register).
12195정성태3/16/202018253.NET Framework: 902. C# - 프로세스의 모든 핸들을 열람 - 세 번째 이야기
12194정성태3/16/202020978오류 유형: 607. PostgreSQL - Npgsql.NpgsqlException: sorry, too many clients already
12193정성태3/16/202017872개발 환경 구성: 485. docker - SAP Adaptive Server Enterprise 컨테이너 실행 [1]
12192정성태3/14/202019896개발 환경 구성: 484. docker - Sybase Anywhere 16 컨테이너 실행
12191정성태3/14/202021022개발 환경 구성: 483. docker - OracleXE 컨테이너 실행 [1]
12190정성태3/14/202015570오류 유형: 606. Docker Desktop 업그레이드 시 "The process cannot access the file 'C:\Program Files\Docker\Docker\resources\dockerd.exe' because it is being used by another process."
12189정성태3/13/202021173개발 환경 구성: 482. Facebook OAuth 처리 시 상태 정보 전달 방법과 "유효한 OAuth 리디렉션 URI" 설정 규칙
12188정성태3/13/202025995Windows: 169. 부팅 시점에 실행되는 chkdsk 결과를 확인하는 방법
12187정성태3/12/202015524오류 유형: 605. NtpClient was unable to set a manual peer to use as a time source because of duplicate error on '...'.
12186정성태3/12/202017381오류 유형: 604. The SysVol Permissions for one or more GPOs on this domain controller and not in sync with the permissions for the GPOs on the Baseline domain controller.
12185정성태3/11/202017960오류 유형: 603. The browser service was unable to retrieve a list of servers from the browser master...
12184정성태3/11/202019888오류 유형: 602. Automatic certificate enrollment for local system failed (0x800706ba) The RPC server is unavailable. [3]
12183정성태3/11/202017692오류 유형: 601. Warning: DsGetDcName returned information for \\[...], when we were trying to reach [...].
... 61  62  63  64  65  66  67  68  [69]  70  71  72  73  74  75  ...