Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 726. ARM 플랫폼용 Visual C++ 리눅스 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 4990
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)
(시리즈 글이 4개 있습니다.)
개발 환경 구성: 722. ARM 플랫폼 빌드를 위한 미니 PC(?) - Khadas VIM4
; https://www.sysnet.pe.kr/2/0/13727

개발 환경 구성: 724. ARM + docker 환경에서 .NET 8 설치
; https://www.sysnet.pe.kr/2/0/13732

개발 환경 구성: 726. ARM 플랫폼용 Visual C++ 리눅스 프로젝트 빌드
; https://www.sysnet.pe.kr/2/0/13735

C/C++: 176. C/C++ - ARM64로 포팅할 때 유의할 점
; https://www.sysnet.pe.kr/2/0/13751




ARM 플랫폼용 Visual C++ 리눅스 프로젝트 빌드

지난 글에 설명한 ARM용 빌드 서버(?)를,

ARM 플랫폼 빌드를 위한 미니 PC(?) - Khadas VIM4
; https://www.sysnet.pe.kr/2/0/13727

Visual C++ 리눅스 프로젝트로 연결해 빌드해 보면, 우선 이런 에러가 발생합니다.

// Platform Toolset == "Clang for Remote Linux"인 경우
error : clang++ exited with code 1, please see the Output Window - Build output for more details (NOTE: the build output verbosity might need to be changed in Tools Options to see more information in the Output Window).

// Platform Toolset == "GCC for Remote Linux"인 경우
error : g++ exited with code 1, please see the Output Window - Build output for more details (NOTE: the build output verbosity might need to be changed in Tools Options to see more information in the Output Window).


역시 예전에 설명한 대로,

$ sudo apt install clang

$ sudo apt install g++ gdb make

clang 또는 g++을 설치하면 됩니다. 추가로, 현재 Visual Studio 2022에서 리눅스 프로젝트를 생성하면 C++ 11이 기본이므로 이런 오류가 발생할 수 있습니다.

error : pasting "u8" and "'H'" does not give a valid preprocessing token

pasting formed 'u8'='', an invalid preprocessing token [-Winvalid-token-paste]

따라서 필요하다면 C++ 17 이상으로 직접 설정해 주어야 합니다.




Khadas VIM4의 경우 안정적인 Ubuntu 버전이 24.04인데요, 그래서 glibc 버전이 다소 높습니다.

$ ldd --version
ldd (Ubuntu GLIBC 2.39-0ubuntu8.2) 2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

$ objdump -p ./testconsole/bin/ARM64/Debug/testconsole.so

./testconsole/bin/ARM64/Debug/testconsole.so:     file format elf64-littleaarch64

...[생략]...

Version References:
  required from ld-linux-aarch64.so.1:
    0x06969197 0x00 05 GLIBC_2.17
  required from libc.so.6:
    0x069691b8 0x00 10 GLIBC_2.38
    0x069691b3 0x00 09 GLIBC_2.33
    0x06969185 0x00 08 GLIBC_2.25
    0x069691b5 0x00 07 GLIBC_2.35
    0x069691b2 0x00 06 GLIBC_2.32
    0x069691b6 0x00 04 GLIBC_2.36
    0x06969197 0x00 03 GLIBC_2.17
    0x069691b4 0x00 02 GLIBC_2.34
private flags = 0x0:

따라서 호환을 높이기 위해 낮은 버전으로 내리는 것이 좋은데요, 이를 위해 docker를 이용하는 것도 좋은 방법입니다.

ARM에서도 docker를 잘 지원하기 때문에,

Getting started with Docker for Arm on Linux
; https://www.docker.com/blog/getting-started-with-docker-for-arm-on-linux/

간단하게 이렇게 설치해 주고,

$ sudo apt-get update && sudo apt-get upgrade -y

$ curl -fsSL test.docker.com -o get-docker.sh && sh get-docker.sh

$ sudo usermod -aG docker $USER 

다시 로그인 후 테스트용 docker를 돌려봅니다.

$ docker run hello-world 

$ docker run -p 15000:15000 hello-world




기본적인 구성이 되었다면, 이제 빌드 환경 및 ssh 데몬을 구축하는 dockerfile을 만들어 봅니다.

Build C++ Applications in a Linux Docker Container with Visual Studio
; https://devblogs.microsoft.com/cppblog/build-c-applications-in-a-linux-docker-container-with-visual-studio/

c:\temp> type dockerfile.ubuntu18.cppbuild

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y g++ clang openssh-server

# configure SSH for communication with Visual Studio 
RUN mkdir -p /var/run/sshd

RUN echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config && ssh-keygen -A 

# expose port 22 
EXPOSE 22

RUN useradd -m -d /home/testusr -s /bin/bash -G sudo testusr

ARG DEFAULT_PASSWORD=testusr_password
RUN echo "testusr:${DEFAULT_PASSWORD}" | chpasswd

WORKDIR /app
RUN echo '#!/bin/bash\n' >> /app/run.sh
RUN echo 'service ssh start\n' >> /app/run.sh
RUN echo 'if [[ -z "${BASH_RUN}" ]]; then\n' >> /app/run.sh
RUN echo '  /bin/bash\n' >> /app/run.sh
RUN echo 'fi\n' >> /app/run.sh

ENTRYPOINT ["/bin/bash", "/app/run.sh"]

혹은 공개키를 등록해 두는 방식도 좋습니다.

c:\temp> echo %USERNAME%
testusr

c:\temp> type dockerfile.ubuntu18.cppbuild
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y g++ clang openssh-server

# configure SSH for communication with Visual Studio 
RUN mkdir -p /var/run/sshd

# expose port 22 
EXPOSE 22

RUN useradd -m -d /home/testusr -s /bin/bash -G sudo testusr

RUN mkdir -p /home/testusr/.ssh

RUN echo 'ssh-rsa AAAAB3N...[생략]...ELhFHJYdYcQ== testusr@192.168.100.50' >> /home/testusr/.ssh/authorized_keys

WORKDIR /app
RUN echo '#!/bin/bash\n' >> /app/run.sh
RUN echo 'service ssh start\n' >> /app/run.sh
RUN echo 'if [[ -z "${BASH_RUN}" ]]; then\n' >> /app/run.sh
RUN echo '  /bin/bash\n' >> /app/run.sh
RUN echo 'fi\n' >> /app/run.sh

ENTRYPOINT ["/bin/bash", "/app/run.sh"]

빌드 후,

c:\temp> set DOCKER_HOST=ssh://testusr@192.168.100.50

// ssh - PasswordAuthentication yes인 경우
c:\temp> docker build -t cpp_ubuntu18_build -f dockerfile.ubuntu18.cppbuild . --build-arg DEFAULT_PASSWORD=testpw

// ssh - 공개키 연결인 경우
c:\temp> docker build -t cpp_ubuntu18_build -f dockerfile.ubuntu18.cppbuild .

실행해 두면 sshd가 대기하게 되고,

c:\temp> docker run -it --rm --name test_cpp_build -p 15000:22 cpp_ubuntu18_build
 * Starting OpenBSD Secure Shell server sshd                                                                     [ OK ]
root@e9efc3d658b5:/app#

별도의 ssh 클라이언트로 접속해 컨테이너로 연결되는 것까지 확인합니다.

c:\temp> ssh testusr@192.168.100.50 -p 15000
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.15.119 aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
Last login: Thu Sep 19 02:17:32 2024 from 192.168.100.20




끝이군요, 이제 Visual Studio에서 해당 컨테이너로의 연결을 추가하고,

Visual Studio - Cross Platform / "Authentication Type: Private Key"로 접속하는 방법
; https://www.sysnet.pe.kr/2/0/13733

프로젝트를 빌드하면 됩니다. 위의 예제에서는 Ubuntu 18.04에서 빌드하기 때문에 빌드 결과물은 glibc 2.27 이상에서 실행 가능합니다.

한 가지 주의할 것은, 향후 dockerfile에 "apt install" 등의 명령어 추가로 docker image가 바뀌는 경우 sshd의 호스트 키까지 변경될 수 있는데, 그럴 때 기존 프로젝트를 빌드하면 이런 오류가 발생할 수 있습니다.

error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.

Failed to connect over SSH due to a host key mismatch. Please go to Tools | Options | Cross Platform | Connection Manager and select "Verify" to resolve this.


메시지에 따라 "Connection Manager"에서 "Verify"를 선택해 새로운 fingerprint를 업데이트하면 되는데요,

Accept Host Key
---------------------------
Warning: remote host '192.168.100.50' identification has changed. ecdsa-sha2-nistp256 host key does not match. 

If you trust the new host key, update the stored host key fingerprint to enable this connection.

The fingerprint sent by the remote host is SHA256:j/8Aq9zxLWxVbhg/7VP8FyV6bxGkBhk/8O9RPTDRJBk. 

The expected fingerprint is SHA256:HzOi+nQy5bbOHTjiBAK9PpSp8uC3oM7yHYyiZDx7+dI. 

Would you like to update the saved fingerprint and continue connecting?

문제는, 이것이 빌드 스크립트 등에서의 상황이었다면 어느 순간 원인도 모르는 황당한 오류가 발생하는 것으로 인식할 수 있다는 점입니다.

이것을 해결하려면, 약간의 귀찮음을 감수해야 하는데요, 우선 서버 측에서의 우회 방법으로 생각나는 것이 있다면 ssh 키를 고정하는 것일 듯합니다. sshd의 경우 host key를 /etc/ssh에 보관하는데,

# cat /etc/ssh/ssh_host_rsa_key.pub
ssh-rsa AAAAB3...[생략]...9E1vQq/T root@buildkitsandbox

# cat /etc/ssh/ssh_host_rsa_key
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAw0jfwr+ICreanu9DUNp3pUmlTjkHzxKE0K14/EUW1XCuJ1r3
...[생략]...
root@8545a41a96ba:/app#
-----END RSA PRIVATE KEY-----

dockerfile에 저 키를 고정하도록 추가하는 방법이 있을 것입니다. 혹은, 클라이언트 측에서, 즉 Visual C++의 리눅스 프로젝트 빌드 전에 fingerprint를 업데이트하는 방법이 있을 것입니다. 이를 위해 ConnectionManager.exe를 빌드 단계 전에 실행할 필요가 있습니다.

C:\temp> ConnectionManager update testusr@192.168.100.50 --port 15000 --no-prompt
Warning: remote host identification has changed. ecdsa-sha2-nistp256 host key does not match.

If you trust the new host key, update the stored host key fingerprint to enable this connection.
The fingerprint sent by the remote host is SHA256:j/8Aq9zxLWxVbhg/7VP8FyV6bxGkBhk/8O9RPTDRJBk.
The expected fingerprint is SHA256:p4zZ3wVFbhlDGjXyTcMHkqgkiCYYj+CCdFTwK6j3WGU.
Warning: accepted key for host '192.168.100.50' (ecdsa-sha2-nistp256).
Successfully modified connection '1144067422;192.168.100.50 (username=testusr, port=15000, authentication=PrivateKey)'.

참고로, Visual Studio는 fingerprint 관리를 "%USERPROFILE%\.ssh\known_hosts" 파일이 아닌, 별도의 store.xml 파일에 보관합니다.




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 9/21/2024]

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)
13844정성태12/14/20243210디버깅 기술: 206. Windbg로 알아보는 PFN (_MMPFN)파일 다운로드1
13843정성태12/13/20242952오류 유형: 938. Docker container 내에서 빌드 시 error MSB3021: Unable to copy file "..." to "...". Access to the path '...' is denied.
13842정성태12/12/20243181디버깅 기술: 205. Windbg - KPCR, KPRCB
13841정성태12/11/20243346오류 유형: 937. error MSB4044: The "ValidateValidArchitecture" task was not given a value for the required parameter "RemoteTarget"
13840정성태12/11/20243177오류 유형: 936. msbuild - Your project file doesn't list 'win' as a "RuntimeIdentifier"
13839정성태12/11/20243168오류 유형: 936. msbuild - error CS1617: Invalid option '12.0' for /langversion. Use '/langversion:?' to list supported values.
13838정성태12/4/20242990오류 유형: 935. Windbg - Breakpoint 0's offset expression evaluation failed.
13837정성태12/3/20243227디버깅 기술: 204. Windbg - 윈도우 핸들 테이블 (3) - Windows 10 이상인 경우
13836정성태12/3/20243470디버깅 기술: 203. Windbg - x64 가상 주소를 물리 주소로 변환 (페이지 크기가 2MB인 경우)
13835정성태12/2/20243406오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty
13834정성태11/29/20243625Windows: 275. C# - CUI 애플리케이션과 Console 윈도우 (Windows 10 미만의 Classic Console 모드인 경우) [1]파일 다운로드1
13833정성태11/29/20243411개발 환경 구성: 737. Azure Web App에서 Scale-out으로 늘어난 리눅스 인스턴스에 SSH 접속하는 방법
13832정성태11/27/20243724Windows: 274. Windows 7부터 도입한 conhost.exe
13831정성태11/27/20243640Linux: 111. eBPF - BPF_MAP_TYPE_PERF_EVENT_ARRAY, BPF_MAP_TYPE_RINGBUF에 대한 다양한 용어들
13830정성태11/25/20243555개발 환경 구성: 736. 파이썬 웹 앱을 Azure App Service에 배포하기
13829정성태11/25/20243544스크립트: 67. 파이썬 - Windows 버전에서 함께 설치되는 py.exe
13828정성태11/25/20243447개발 환경 구성: 735. Azure - 압축 파일을 이용한 web app 배포 시 디렉터리 구분이 안 되는 문제파일 다운로드1
13827정성태11/25/20243694Windows: 273. Windows 환경의 파일 압축 방법 (tar, Compress-Archive)
13826정성태11/21/20243887닷넷: 2313. C# - (비밀번호 등의) Console로부터 입력받을 때 문자열 출력 숨기기(echo 끄기)파일 다운로드1
13825정성태11/21/20243894Linux: 110. eBPF / bpf2go - BPF_RINGBUF_OUTPUT / BPF_MAP_TYPE_RINGBUF 사용법
13824정성태11/20/20243811Linux: 109. eBPF / bpf2go - BPF_PERF_OUTPUT / BPF_MAP_TYPE_PERF_EVENT_ARRAY 사용법
13823정성태11/20/20243593개발 환경 구성: 734. Ubuntu에 docker, kubernetes (k3s) 설치
13822정성태11/20/20243472개발 환경 구성: 733. Windbg - VirtualBox VM의 커널 디버거 연결 시 COM 포트가 없는 경우
13821정성태11/18/20243532Linux: 108. Linux와 Windows의 프로세스/스레드 ID 관리 방식
13820정성태11/18/20243550VS.NET IDE: 195. Visual C++ - C# 프로젝트처럼 CopyToOutputDirectory 항목을 추가하는 방법
13819정성태11/15/20243592Linux: 107. eBPF - libbpf CO-RE의 CONFIG_DEBUG_INFO_BTF 빌드 여부에 대한 의존성
1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...