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)
13578정성태3/11/20241631닷넷: 2230. C# - 덮어쓰기 가능한 환형 큐 (Circular queue)파일 다운로드1
13577정성태3/9/20241878닷넷: 2229. C# - 닷넷을 위한 난독화 도구 소개 (예: ConfuserEx)
13576정성태3/8/20241545닷넷: 2228. .NET Profiler - IMetaDataEmit2::DefineMethodSpec 사용법
13575정성태3/7/20241679닷넷: 2227. 최신 C# 문법을 .NET Framework 프로젝트에 쓸 수 있을까요?
13574정성태3/6/20241558닷넷: 2226. C# - "Docker Desktop for Windows" Container 환경에서의 IPv6 DualMode 소켓
13573정성태3/5/20241567닷넷: 2225. Windbg - dumasync로 분석하는 async/await 호출
13572정성태3/4/20241645닷넷: 2224. C# - WPF의 Dispatcher Queue로 알아보는 await 호출의 hang 현상파일 다운로드1
13571정성태3/1/20241624닷넷: 2223. C# - await 호출과 WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13570정성태2/29/20241636닷넷: 2222. C# - WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13569정성태2/28/20241546닷넷: 2221. C# - LoadContext, LoadFromContext 그리고 GAC파일 다운로드1
13568정성태2/27/20241608닷넷: 2220. C# - .NET Framework 프로세스의 LoaderOptimization 설정을 확인하는 방법파일 다운로드1
13567정성태2/27/20241618오류 유형: 898. .NET Framework 3.5 이하에서 mscoree.tlb 참조 시 System.BadImageFormatException파일 다운로드1
13566정성태2/27/20241632오류 유형: 897. Windows 7 SDK 설치 시 ".NET Development" 옵션이 비활성으로 선택이 안 되는 경우
13565정성태2/23/20241479닷넷: 2219. .NET CLR2 보안 모델에서의 개별 System.Security.Permissions 제어
13564정성태2/22/20241614Windows: 259. Hyper-V Generation 1 유형의 VM을 Generation 2 유형으로 바꾸는 방법
13563정성태2/21/20241651디버깅 기술: 196. windbg - async/await 비동기인 경우 메모리 덤프 분석의 어려움
13562정성태2/21/20241648오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
13561정성태2/20/20241747닷넷: 2218. C# - (예를 들어, Socket) 비동기 I/O에 대한 await 호출 시 CancellationToken을 이용한 취소파일 다운로드1
13560정성태2/19/20241749디버깅 기술: 195. windbg 분석 사례 - Semaphore 잠금으로 인한 Hang 현상 (닷넷)
13559정성태2/19/20242626오류 유형: 895. ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'
13558정성태2/18/20241822닷넷: 2217. C# - 최댓값이 1인 SemaphoreSlim 보다 Mutex 또는 lock(obj)를 선택하는 것이 나은 이유
13557정성태2/18/20241622Windows: 258. Task Scheduler의 Author 속성 값을 변경하는 방법
13556정성태2/17/20241685Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점
13555정성태2/15/20241959닷넷: 2216. C# - SemaphoreSlim 사용 시 주의점
13554정성태2/15/20241710VS.NET IDE: 189. Visual Studio - 닷넷 소스코드 디컴파일 찾기가 안 될 때
13553정성태2/14/20241737닷넷: 2215. windbg - thin/fat lock 없이 동작하는 Monitor.Wait + Pulse
1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...