Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Visual Studio 2019 버전 16.1부터 리눅스 C/C++ 프로젝트에 추가된 WSL 지원

드디어, 리눅스 C/C++ 프로젝트가 WSL에 자연스럽게 통합했습니다.

C++ with Visual Studio 2019 and Windows Subsystem for Linux (WSL)
; https://devblogs.microsoft.com/cppblog/c-with-visual-studio-2019-and-windows-subsystem-for-linux-wsl/

AddressSanitizer (ASan) for the Linux Workload in Visual Studio 2019
; https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-the-linux-workload-in-visual-studio-2019/

방법도 간단합니다. WSL 측에 다음과 같이 기본적인 개발 도구를 설치하고,

$ sudo apt install g++ gdb make rsync zip

Visual Studio의 리눅스 프로젝트에서는 "Platform Toolset" 설정을 (기본값 Remote_GCC_1_0으로부터) WSL_1_0으로 바꿔주기만 하면 됩니다.

vs_wsl_support_1.png

여기서 주의할 것은 위의 화면에서 "Platform Toolset"의 하단에 "WSL .exe full path"로 입력된 값이 기본적으로는 "Bash on Ubuntu on Windows"라는 점입니다. 이것은 윈도우 스토어에서 설치한 "Ubuntu - Trusted Microsoft Store App"과 같이,

Ubuntu 18.04 LTS
; https://www.microsoft.com/en-us/p/ubuntu-1804-lts/9n9tngvndl3q

다른 리눅스 배포본과는 다른 경로입니다. 자신의 환경에 어떤 리눅스 배포판이 설치되어 있는지 "wslconfig /l" 명령어로 확인해 보면,

C:\> wslconfig /l
Windows Subsystem for Linux Distributions:
Legacy (Default)
Ubuntu

"WSL .exe full path"의 기본값인 "$(windir)\sysnative\wsl.exe"는 "Legacy (Default)"에 해당하는 것으로 앱 제목이 "Bash on Ubuntu on Windows"에 해당합니다. 따라서 만약, Windows Store로부터 받은 "Ubuntu"와 연동하고 싶다면 "WSL .exe full path" 값을 다음과 같은 식으로 바꿔줘야 합니다.

C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2018.817.0_x64__79rhkp1fndgsc\ubuntu.exe

(위의 경로는 Ubuntu 앱을 실행하고 작업 관리자를 통해 알 수 있습니다.)

참고로 환경 정보를 출력해 보면,

#include <cstdio>
#include <sys/utsname.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

using namespace std;

string read_file(const char* filePath)
{
    string txt(4096, 0);

    int fd = open(filePath, O_RDONLY);
    read(fd, (void *)txt.data(), txt.size() - 1);

    close(fd);

    return txt;
}

int main()
{
    utsname info;
    uname(&info);
    
    printf("%s, %s, %s, %s, %s\n", info.sysname, info.nodename, info.release, info.version, info.machine);

    string txt = read_file("/etc/lsb-release");
    printf("%s", txt.c_str());

    return 0;
}

이런 차이가 있습니다.

[Bash on Ubuntu on Windows의 경우]
Linux, TESTPC, 4.4.0-17763-Microsoft, #379-Microsoft Wed Mar 06 19:16:00 PST 2019, x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"

[StoreApp Ubuntu의 경우]
Linux, TESTPC, 4.4.0-17763-Microsoft, #379-Microsoft Wed Mar 06 19:16:00 PST 2019, x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"




개인적으로 현재 Visual Studio로 리눅스 프로젝트를 진행하고 있어서 기대를 많이 했습니다. ^^ 그런데, 아직 좀 기다려야겠습니다. 왜냐하면, 일단 인텔리센스가 안 됩니다. WSL이 아닌 경우, 원격 리눅스로 SSH 연결 설정을 해 두면 자동으로 헤더 파일을 다운로드해 연동이 되는데요. WSL의 경우에는 그게 아니어도 된다고는 하지만,

In Visual Studio you no longer need to add a remote connection or configure SSH in order to build and debug on your local WSL installation.


어쨌든 결과적으로 인텔리센스가 동작하지 않습니다. (헤더 파일들에 전부 빨간색 밑줄이 그어집니다.) 그래도 이 부분은 경험이 있다면 WSL에 SSH 연결 설정하고 다운로드한 헤더 파일의 폴더를 리눅스 프로젝트에 설정하는 것으로 해결할 수 있습니다.

결정적으로 불편한게 하나 있다면, 실행할 때마다 빌드를 새롭게 한다는 점입니다. 아마도 이것은 조만간 수정될 듯하지만 그때까지는 일단 현재 프로젝트를 WSL로 변경하는 것은 미루기로 했습니다. (어차피 "Platform Toolset" 옵션 하나 변경하는 것이지만. ^^)

그 외에는 전체적으로 깔끔하게 통합된 것은 사실입니다.




참고로, 빌드 결과물이 다음과 같은 식의 경로에 남기 때문에,

F:\ConsoleApplication1\ConsoleApplication1\bin\x64\Debug\ConsoleApplication1.out

Ubuntu App에서 곧바로 테스트할 수 있습니다.

$ cd /mnt/f/ConsoleApplication1/ConsoleApplication1/bin/x64/Debug
$ ./ConsoleApplication1.out
Linux, THE11, 4.4.0-17763-Microsoft, #379-Microsoft Wed Mar 06 19:16:00 PST 2019, x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"




빌드 시 다음과 같은 오류가 발생한다면?

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Linux.WSL.targets(188,5): error MSB4018: The "Compile" task failed unexpectedly.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Linux.WSL.targets(188,5): error MSB4018: liblinux.Local.WindowsSubsystemException: Could not find the WSL launcher: '"C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2018.817.0_x64__79rhkp1fndgsc\ubuntu.exe"'.

프로젝트 속성 창의 "WSL .exe full path"에 준 경로가 올바르지 않아서입니다. 가령 겹따옴표를 붙이면,

"C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2018.817.0_x64__79rhkp1fndgsc\ubuntu.exe"

Compile task에서 오류가 발생하므로 반드시 겹따옴표를 제거해야 합니다.

C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2018.817.0_x64__79rhkp1fndgsc\ubuntu.exe




또는, F5 디버깅을 눌렀을 때 다음과 같은 메시지가 나온다면?

Could not launch gdb. gdb is missing from your WSL system and needs to be installed, please use your system's package manager to install it.


대상 WSL 리눅스 배포본에 개발 관련 도구들이 설치되어 있지 않은 것입니다. 혹시나 "WSL .exe full path"에 지정한 리눅스 배포본과 개발 도구를 설치한 배포본이 동일한 것인지 확인해 볼 필요가 있습니다.




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/8/2022]

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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  [21]  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13098정성태7/13/20226082개발 환경 구성: 647. Azure - scale-out 상태의 App Service에서 특정 인스턴스에 요청을 보내는 방법 [1]
13097정성태7/12/20225490오류 유형: 817. Golang - binary.Read: invalid type int32
13096정성태7/8/20228242.NET Framework: 2030. C# 11 - UTF-8 문자열 리터럴
13095정성태7/7/20226321Windows: 208. AD 도메인에 참여하지 않은 컴퓨터에서 Kerberos 인증을 사용하는 방법
13094정성태7/6/20226023오류 유형: 816. Golang - "short write" 오류 원인
13093정성태7/5/20226950.NET Framework: 2029. C# - HttpWebRequest로 localhost 접속 시 2초 이상 지연
13092정성태7/3/20227886.NET Framework: 2028. C# - HttpWebRequest의 POST 동작 방식파일 다운로드1
13091정성태7/3/20226704.NET Framework: 2027. C# - IPv4, IPv6를 모두 지원하는 서버 소켓 생성 방법
13090정성태6/29/20225837오류 유형: 815. PyPI에 업로드한 패키지가 반영이 안 되는 경우
13089정성태6/28/20226321개발 환경 구성: 646. HOSTS 파일 변경 시 Edge 브라우저에 반영하는 방법
13088정성태6/27/20225442개발 환경 구성: 645. "Developer Command Prompt for VS 2022" 명령행 환경의 폰트를 바꾸는 방법
13087정성태6/23/20228398스크립트: 41. 파이썬 - FastAPI / uvicorn 호스팅 환경에서 asyncio 사용하는 방법 [1]
13086정성태6/22/20227815.NET Framework: 2026. C# 11 - 문자열 보간 개선 2가지파일 다운로드1
13085정성태6/22/20227876.NET Framework: 2025. C# 11 - 원시 문자열 리터럴(raw string literals)파일 다운로드1
13084정성태6/21/20226518개발 환경 구성: 644. Windows - 파이썬 2.7을 msi 설치 없이 구성하는 방법
13083정성태6/20/20227090.NET Framework: 2024. .NET 7에 도입된 GC의 메모리 해제에 대한 segment와 region의 차이점 [2]
13082정성태6/19/20226135.NET Framework: 2023. C# - Process의 I/O 사용량을 보여주는 GetProcessIoCounters Win32 API파일 다운로드1
13081정성태6/17/20226210.NET Framework: 2022. C# - .NET 7 Preview 5 신규 기능 - System.IO.Stream ReadExactly / ReadAtLeast파일 다운로드1
13080정성태6/17/20226827개발 환경 구성: 643. Visual Studio 2022 17.2 버전에서 C# 11 또는 .NET 7.0 preview 적용
13079정성태6/17/20224569오류 유형: 814. 파이썬 - Error: The file/path provided (...) does not appear to exist
13078정성태6/16/20226588.NET Framework: 2021. WPF - UI Thread와 Render Thread파일 다운로드1
13077정성태6/15/20226921스크립트: 40. 파이썬 - PostgreSQL 환경 구성
13075정성태6/15/20225881Linux: 50. Linux - apt와 apt-get의 차이 [2]
13074정성태6/13/20226183.NET Framework: 2020. C# - NTFS 파일에 사용자 정의 속성값 추가하는 방법파일 다운로드1
13073정성태6/12/20226389Windows: 207. Windows Server 2022에 도입된 WSL 2
13072정성태6/10/20226680Linux: 49. Linux - ls 명령어로 출력되는 디렉터리 색상 변경 방법
... 16  17  18  19  20  [21]  22  23  24  25  26  27  28  29  30  ...