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)
12868정성태12/7/20216825오류 유형: 770. twine 업로드 시 "HTTPError: 400 Bad Request ..." 오류 [1]
12867정성태12/7/20216537개발 환경 구성: 612. 파이썬 - PyPI 패키지 만들기 (3) entry_points 옵션
12866정성태12/7/202113910오류 유형: 769. "docker build ..." 시 "failed to solve with frontend dockerfile.v0: failed to read dockerfile ..." 오류
12865정성태12/6/20216606개발 환경 구성: 611. 파이썬 - PyPI 패키지 만들기 (2) long_description, cmdclass 옵션
12864정성태12/6/20215083Linux: 46. WSL 환경에서 find 명령을 사용해 파일을 찾는 방법
12863정성태12/4/20216963개발 환경 구성: 610. 파이썬 - PyPI 패키지 만들기
12862정성태12/3/20215716오류 유형: 768. Golang - 빌드 시 "cmd/go: unsupported GOOS/GOARCH pair linux /amd64" 오류
12861정성태12/3/20217941개발 환경 구성: 609. 파이썬 - "Windows embeddable package"로 개발 환경 구성하는 방법
12860정성태12/1/20216047오류 유형: 767. SQL Server - 127.0.0.1로 접속하는 경우 "Access is denied"가 발생한다면?
12859정성태12/1/202112169개발 환경 구성: 608. Hyper-V 가상 머신에 Console 모드로 로그인하는 방법
12858정성태11/30/20219424개발 환경 구성: 607. 로컬의 USB 장치를 원격 머신에 제공하는 방법 - usbip-win
12857정성태11/24/20216935개발 환경 구성: 606. WSL Ubuntu 20.04에서 파이썬을 위한 uwsgi 설치 방법
12856정성태11/23/20218674.NET Framework: 1121. C# - 동일한 IP:Port로 바인딩 가능한 서버 소켓 [2]
12855정성태11/13/20216078개발 환경 구성: 605. Azure App Service - Kudu SSH 환경에서 FTP를 이용한 파일 전송
12854정성태11/13/20217628개발 환경 구성: 604. Azure - 윈도우 VM에서 FTP 여는 방법
12853정성태11/10/20216003오류 유형: 766. Azure App Service - JBoss 호스팅 생성 시 "This region has quota of 0 PremiumV3 instances for your subscription. Try selecting different region or SKU."
12851정성태11/1/20217360스크립트: 34. 파이썬 - MySQLdb 기본 예제 코드
12850정성태10/27/20218508오류 유형: 765. 우분투에서 pip install mysqlclient 실행 시 "OSError: mysql_config not found" 오류
12849정성태10/17/20217642스크립트: 33. JavaScript와 C#의 시간 변환 [1]
12848정성태10/17/20218614스크립트: 32. 파이썬 - sqlite3 기본 예제 코드 [1]
12847정성태10/14/20218466스크립트: 31. 파이썬 gunicorn - WORKER TIMEOUT 오류 발생
12846정성태10/7/20218245스크립트: 30. 파이썬 __debug__ 플래그 변수에 따른 코드 실행 제어
12845정성태10/6/20218069.NET Framework: 1120. C# - BufferBlock<T> 사용 예제 [5]파일 다운로드1
12844정성태10/3/20216109오류 유형: 764. MSI 설치 시 "... is accessible and not read-only." 오류 메시지
12843정성태10/3/20216581스크립트: 29. 파이썬 - fork 시 기존 클라이언트 소켓 및 스레드의 동작파일 다운로드1
12842정성태10/1/202124742오류 유형: 763. 파이썬 오류 - AttributeError: type object '...' has no attribute '...'
... 16  17  18  19  20  21  22  23  24  25  26  27  28  29  [30]  ...