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)
13044정성태5/4/20226294오류 유형: 808. error : clang++ exited with code 127
13043정성태5/3/20225922오류 유형: 807. C# - 닷넷 응용 프로그램에서 Informix DB 사용 시 오류 메시지 정리
13042정성태5/3/20226312.NET Framework: 2000. C# - 닷넷 응용 프로그램에서 Informix DB 사용 방법파일 다운로드1
13041정성태4/28/20226577개발 환경 구성: 642. Informix 데이터베이스 docker 환경 구성
13040정성태4/27/20227118VC++: 156. 비주얼 스튜디오 - Linux C/C++ 프로젝트에서 openssl 링크하는 방법
13039정성태4/27/20227875.NET Framework: 1999. C# - Playwright를 이용한 간단한 브라우저 제어 실습
13038정성태4/26/20225801오류 유형: 806. twine 실행 시 ConfigParser.ParsingError: File contains parsing errors: /root/.pypirc
13037정성태4/25/20226110.NET Framework: 1998. Azure Functions를 사용한 간단한 실습
13036정성태4/24/20226832.NET Framework: 1997. C# - nano 시간을 가져오는 방법 [2]
13035정성태4/22/20227392Windows: 204. Windows 10부터 바뀐 QueryPerformanceFrequency, QueryPerformanceCounter
13034정성태4/21/20226810.NET Framework: 1996. C# XingAPI - 주식 종목에 따른 PBR, PER, ROE, ROA 구하는 방법(t3320, t8430 예제)파일 다운로드1
13033정성태4/18/20227407.NET Framework: 1195. C# - Thread.Yield와 Thread.Sleep(0)의 차이점(?)
13032정성태4/17/20227083오류 유형: 805. Github의 50MB 파일 크기 제한 - warning: GH001: Large files detected. You may want to try Git Large File Storage
13031정성태4/15/20226628.NET Framework: 1194. C# - IdealProcessor와 ProcessorAffinity의 차이점
13030정성태4/15/20226327오류 유형: 804. 정규 표현식 오류 - Quantifier {x,y} following nothing.
13029정성태4/14/20226709Windows: 203. iisreset 후에도 이전에 설정한 전역 환경 변수가 w3wp.exe에 적용되는 문제
13028정성태4/13/20226608.NET Framework: 1193. (appsettings.json처럼) web.config의 Debug/Release에 따른 설정 적용
13027정성태4/12/20226907.NET Framework: 1192. C# - 환경 변수의 변화를 알리는 WM_SETTINGCHANGE Win32 메시지 사용법파일 다운로드1
13026정성태4/11/20228435.NET Framework: 1191. C 언어로 작성된 FFmpeg Examples의 C# 포팅 전체 소스 코드 [3]
13025정성태4/11/20227797.NET Framework: 1190. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 vaapi_encode.c, vaapi_transcode.c 예제 포팅
13024정성태4/7/20226310.NET Framework: 1189. C# - 런타임 환경에 따라 달라진 AppDomain.GetCurrentThreadId 메서드
13023정성태4/6/20226619.NET Framework: 1188. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 transcoding.c 예제 포팅 [3]
13022정성태3/31/20226497Windows: 202. 윈도우 11 업그레이드 - "PC Health Check"를 통과했지만 여전히 업그레이드가 안 되는 경우 해결책
13021정성태3/31/20226651Windows: 201. Windows - INF 파일을 이용한 장치 제거 방법
13020정성태3/30/20226416.NET Framework: 1187. RDP 접속 시 WPF UserControl의 Unloaded 이벤트 발생파일 다운로드1
13019정성태3/30/20226390.NET Framework: 1186. Win32 Message를 Code로부터 메시지 이름 자체를 구하고 싶다면?파일 다운로드1
... 16  17  18  19  20  21  22  [23]  24  25  26  27  28  29  30  ...