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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...
NoWriterDateCnt.TitleFile(s)
13299정성태3/27/20233737Windows: 237. Win32 - 모든 메시지 루프를 탈출하는 WM_QUIT 메시지
13298정성태3/27/20233684Windows: 236. Win32 - MessageBeep 소리가 안 들린다면?
13297정성태3/26/20234359Windows: 235. Win32 - Code Modal과 UI Modal
13296정성태3/25/20233700Windows: 234. IsDialogMessage와 협업하는 WM_GETDLGCODE Win32 메시지 [1]파일 다운로드1
13295정성태3/24/20233968Windows: 233. Win32 - modeless 대화창을 modal처럼 동작하게 만드는 방법파일 다운로드1
13294정성태3/22/20234141.NET Framework: 2105. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리 - 두 번째
13293정성태3/22/20234207오류 유형: 853. dumpbin - warning LNK4048: Invalid format file; ignored
13292정성태3/21/20234333Windows: 232. C/C++ - 일반 창에도 사용 가능한 IsDialogMessage파일 다운로드1
13291정성태3/20/20234746.NET Framework: 2104. C# Windows Forms - WndProc 재정의와 IMessageFilter 사용 시의 차이점
13290정성태3/19/20234252.NET Framework: 2103. C# - 윈도우에서 기본 제공하는 FindText 대화창 사용법파일 다운로드1
13289정성태3/18/20233445Windows: 231. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 자식 윈도우를 생성하는 방법파일 다운로드1
13288정성태3/17/20233556Windows: 230. Win32 - 대화창의 DLU 단위를 pixel로 변경하는 방법파일 다운로드1
13287정성태3/16/20233713Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/20234169Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/20233761Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법파일 다운로드1
13284정성태3/13/20233956Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/20233499오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/20233822Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/20233741Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/20234500개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/20234048오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
13278정성태3/8/20234025개발 환경 구성: 669. WSL 2의 (init이 아닌) systemd 지원 [1]
13277정성태3/6/20234666개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/20234338.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어
13275정성태3/3/20234696.NET Framework: 2101. C# 11의 ref 필드 설명
13274정성태3/2/20234278.NET Framework: 2100. C# - ref 필드로 ref struct 타입을 허용하지 않는 이유
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...