Microsoft MVP성태의 닷넷 이야기
VS.NET IDE: 192. Visual Studio 2022 - Windows XP / 2003용 C/C++ 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 7062
글쓴 사람
정성태 (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)
12886정성태12/20/202114690스크립트: 37. 파이썬 - uwsgi의 --enable-threads 옵션 [2]
12885정성태12/20/202115713오류 유형: 776. uwsgi-plugin-python3 환경에서 MySQLdb 사용 환경
12884정성태12/20/202114635개발 환경 구성: 620. Windows 10+에서 WMI root/Microsoft/Windows/WindowsUpdate 네임스페이스 제거
12883정성태12/19/202115070오류 유형: 775. uwsgi-plugin-python3 환경에서 "ModuleNotFoundError: No module named 'django'" 오류 발생
12882정성태12/18/202114563개발 환경 구성: 619. Windows Server에서 WSL을 위한 리눅스 배포본을 설치하는 방법
12881정성태12/17/202114172개발 환경 구성: 618. WSL Ubuntu 20.04에서 파이썬을 위한 uwsgi 설치 방법 (2)
12880정성태12/16/202115161VS.NET IDE: 170. Visual Studio에서 .NET Core/5+ 역어셈블 소스코드 확인하는 방법
12879정성태12/16/202121705오류 유형: 774. Windows Server 2022 + docker desktop 설치 시 WSL 2로 선택한 경우 "Failed to deploy distro docker-desktop to ..." 오류 발생
12878정성태12/15/202115965개발 환경 구성: 617. 윈도우 WSL 환경에서 같은 종류의 리눅스를 다중으로 설치하는 방법
12877정성태12/15/202115277스크립트: 36. 파이썬 - pymysql 기본 예제 코드
12876정성태12/14/202115141개발 환경 구성: 616. Custom Sources를 이용한 Azure Monitor Metric 만들기
12875정성태12/13/202114012스크립트: 35. python - time.sleep(...) 호출 시 hang이 걸리는 듯한 문제
12874정성태12/13/202113852오류 유형: 773. shell script 실행 시 "$'\r': command not found" 오류
12873정성태12/12/202115239오류 유형: 772. 리눅스 - PATH에 등록했는데도 "command not found"가 나온다면?
12872정성태12/12/202115624개발 환경 구성: 615. GoLang과 Python 빌드가 모두 가능한 docker 이미지 만들기
12871정성태12/12/202114683오류 유형: 771. docker: Error response from daemon: OCI runtime create failed
12870정성태12/9/202113753개발 환경 구성: 614. 파이썬 - PyPI 패키지 만들기 (4) package_data 옵션
12869정성태12/8/202116454개발 환경 구성: 613. git clone 실행 시 fingerprint 묻는 단계를 생략하는 방법
12868정성태12/7/202114826오류 유형: 770. twine 업로드 시 "HTTPError: 400 Bad Request ..." 오류 [1]
12867정성태12/7/202114596개발 환경 구성: 612. 파이썬 - PyPI 패키지 만들기 (3) entry_points 옵션
12866정성태12/7/202121493오류 유형: 769. "docker build ..." 시 "failed to solve with frontend dockerfile.v0: failed to read dockerfile ..." 오류
12865정성태12/6/202114837개발 환경 구성: 611. 파이썬 - PyPI 패키지 만들기 (2) long_description, cmdclass 옵션
12864정성태12/6/202112512Linux: 46. WSL 환경에서 find 명령을 사용해 파일을 찾는 방법
12863정성태12/4/202114697개발 환경 구성: 610. 파이썬 - PyPI 패키지 만들기
12862정성태12/3/202112649오류 유형: 768. Golang - 빌드 시 "cmd/go: unsupported GOOS/GOARCH pair linux /amd64" 오류
12861정성태12/3/202116480개발 환경 구성: 609. 파이썬 - "Windows embeddable package"로 개발 환경 구성하는 방법 [1]
... 31  32  33  34  35  36  37  38  39  40  41  [42]  43  44  45  ...