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

Visual Studio - 리눅스 용 프로젝트의 인텔리센스를 위한 헤더 파일 처리 방법

리눅스 용 프로젝트를 Visual Studio에서 만들어 컴파일하는 방법을 소개했었는데요.

WSL을 이용해 윈도우 PC 1대에서 Linux 응용 프로그램을 Visual Studio로 개발하는 방법
; https://www.sysnet.pe.kr/2/0/11390

문제는, 다음과 같이 unistd.h 등의 리눅스 전용 헤더 파일을 추가하는 경우,

#include <cstdio>
#include <unistd.h>

int main()
{
    printf("hello from app4!\n");

    while (true)
    {
        sleep(1); // 인텔리센스가 sleep 함수를 나열하지 못함
    }

    return 0;
}

비주얼 스튜디오가 있는 윈도우 환경에는 해당 헤더 파일이 없기 때문에 'cannot open source file "unistd.h"'라는 오류 메시지와 함께 인텔리센스(Intellisense) 기능이 제공되지 않습니다.

이에 대한 문제를 해결하는 방법은 간단합니다.

Linux header file not recognized in Visual Studio 2017 Linux Project
; https://stackoverflow.com/questions/43022494/linux-header-file-not-recognized-in-visual-studio-2017-linux-project

즉, 비주얼 스튜디오에서 리눅스 프로젝트에 대해서도 unistd.h 파일을 발견할 수 있도록 해주면 되는 것입니다. 사실 비주얼 스튜디오의 경우 기본적인 리눅스 헤더 파일을 다음의 경로에 보관하고 있습니다.

[Visual Studio 2015]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include

[Visual Studio 2017]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\Linux\include

당연히 unistd.h 파일을 저 위치에 복사해 주면 되겠지만 문제는, 일일이 그럴 때마다 파일을 복사해 주는 것은 별로 좋은 방법은 아닌 듯합니다. 바로 이럴 때 윈도우 스토어에 설치했던 Ubuntu 앱이 유용하게 사용됩니다. ^^ 즉, 거기에 이미 구성한 헤더 파일을 포함하면 모든 것이 매끄럽게 해결될 수 있는 것입니다.

우분투 앱에 설치된 모든 파일은 윈도우 파일 시스템으로도 접근할 수 있기 때문에 다음과 같이 검색할 수 있습니다.

C:> dir /a/s unistd.h

검색해 보면 아래는 다음의 경로가 리눅스 용 헤더 파일을 포함하고 있는 것으로 보입니다.

%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\usr\include

그런데 경로가 매우 심란하군요. ^^; 이럴 때는 JUNCTION으로 연결해 주고,

mkdir c:\linux
mklink /J "C:\linux\include" "%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\usr\include"

비주얼 스튜디오에서는 간단하게 c:\linux\include로 설정하면 됩니다.

wsl_header_0.png

이후부터는 다음과 같이 인텔리센스가 아주 잘 적용됩니다. ^^

wsl_header_1.png




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 12/8/2017]

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

비밀번호

댓글 작성자
 



2018-04-09 11시33분
현재 15.7 Preview 3 버전에서 자동으로 원격의 리눅스 헤더 파일을 처리해 인텔리센스를 제공하는 기능이 추가되었다고 합니다. ^^

IntelliSense for Remote Linux Headers
; https://devblogs.microsoft.com/cppblog/intellisense-for-remote-linux-headers/
정성태
2018-08-17 02시25분
Visual Studio 2017로 완벽한 C++ 리눅스 개발환경 만들기
 ; http://www.gamecodi.com/board/zboard-id-GAMECODI_Talkdev-no-5010-z-0.htm
정성태
2018-11-11 02시19분
[erica] 와 정말 꿀팁입니다. 감사합니다.!
[guest]

... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12411정성태11/12/20209840오류 유형: 680. C# 9.0 - Error CS8889 The target runtime doesn't support extensible or runtime-environment default calling conventions.
12410정성태11/12/20209784디버깅 기술: 174. windbg - System.TypeLoadException 예외 분석 사례
12409정성태11/12/202011178.NET Framework: 968. C# 9.0의 Function pointer를 이용한 함수 주소 구하는 방법파일 다운로드1
12408정성태11/9/202022632도서: 시작하세요! C# 9.0 프로그래밍 [8]
12407정성태11/9/202011456.NET Framework: 967. "clr!JIT_DbgIsJustMyCode" 호출이 뭘까요?
12406정성태11/8/202013046.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202010509.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202011017.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202011092.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202011670.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202010593VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/20207594오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202011244.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/20209753오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/20209892.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208258VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209584오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20207988오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/20208474오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202012590.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202010791디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
12389정성태11/1/202010622.NET Framework: 958. C# 9.0 - (8) 정적 익명 함수 (static anonymous functions)파일 다운로드1
12388정성태10/29/202010050오류 유형: 674. 어느 순간부터 닷넷 응용 프로그램 실행 시 System.Configuration.ConfigurationErrorsException 예외가 발생한다면?
12387정성태10/28/202010805.NET Framework: 957. C# - static 필드의 정보가 GC Heap에 저장될까요? [3]파일 다운로드1
12386정성태10/28/202011056Linux: 34. 사용자 정보를 함께 출력하는 리눅스의 ps 명령어 사용 방법
12385정성태10/28/20208815오류 유형: 673. openssl - req: No value provided for Subject Attribute CN, skipped
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...