Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 726. ARM 플랫폼용 Visual C++ 리눅스 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 6046
글쓴 사람
정성태 (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)
13667정성태7/7/20246599닷넷: 2273. C# - 리눅스 환경에서의 Hyper-V Socket 연동 (AF_VSOCK)파일 다운로드1
13666정성태7/7/20247679Linux: 74. C++ - Vsock 예제 (Hyper-V Socket 연동)파일 다운로드1
13665정성태7/6/20247851Linux: 73. Linux 측의 socat을 이용한 Hyper-V 호스트와의 vsock 테스트파일 다운로드1
13663정성태7/5/20247467닷넷: 2272. C# - Hyper-V Socket 통신(AF_HYPERV, AF_VSOCK)의 VMID Wildcards 유형파일 다운로드1
13662정성태7/4/20247470닷넷: 2271. C# - WSL 2 VM의 VM ID를 알아내는 방법 - Host Compute System API파일 다운로드1
13661정성태7/3/20247387Linux: 72. g++ - 다른 버전의 GLIBC로 소스코드 빌드
13660정성태7/3/20247495오류 유형: 912. Visual C++ - Linux 프로젝트 빌드 오류
13659정성태7/1/20247836개발 환경 구성: 715. Windows - WSL 2 환경의 Docker Desktop 네트워크
13658정성태6/28/20248207개발 환경 구성: 714. WSL 2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법 - 두 번째 이야기
13657정성태6/27/20247890닷넷: 2270. C# - Hyper-V Socket 통신(AF_HYPERV, AF_VSOCK)을 위한 EndPoint 사용자 정의
13656정성태6/27/20248051Windows: 264. WSL 2 VM의 swap 파일 위치
13655정성태6/24/20247830닷넷: 2269. C# - Win32 Resource 포맷 해석파일 다운로드1
13654정성태6/24/20247778오류 유형: 911. shutdown - The entered computer name is not valid or remote shutdown is not supported on the target computer.
13653정성태6/22/20247914닷넷: 2268. C# 코드에서 MAKEINTREOURCE 매크로 처리
13652정성태6/21/20249227닷넷: 2267. C# - Linux 환경에서 (Reflection 없이) DLL AssemblyFileVersion 구하는 방법파일 다운로드2
13651정성태6/19/20248464닷넷: 2266. C# - (Reflection 없이) DLL AssemblyFileVersion 구하는 방법파일 다운로드1
13650정성태6/18/20248386개발 환경 구성: 713. "WSL --debug-shell"로 살펴보는 WSL 2 VM의 리눅스 환경
13649정성태6/18/20247941오류 유형: 910. windbg - !py 확장 명령어 실행 시 "failed to find python interpreter" (2)
13648정성태6/17/20248255오류 유형: 909. C# - DynamicMethod 사용 시 System.TypeAccessException
13647정성태6/16/20249307개발 환경 구성: 712. Windows - WSL 2의 네트워크 통신 방법 - 세 번째 이야기 (같은 IP를 공유하는 WSL 2 인스턴스) [1]
13646정성태6/14/20247729오류 유형: 908. Process Explorer - "Error configuring dump resources: The system cannot find the file specified."
13645정성태6/13/20248194개발 환경 구성: 711. Visual Studio로 개발 시 기본 등록하는 dev tag 이미지로 Docker Desktop k8s에서 실행하는 방법
13644정성태6/12/20248840닷넷: 2265. C# - System.Text.Json의 기본적인 (한글 등에서의) escape 처리 [1]
13643정성태6/12/20248293오류 유형: 907. MySqlConnector 사용 시 System.IO.FileLoadException 오류
13642정성태6/11/20248186스크립트: 65. 파이썬 - asgi 버전(2, 3)에 따라 달라지는 uvicorn 호스팅
13641정성태6/11/20248649Linux: 71. Ubuntu 20.04를 22.04로 업데이트
1  2  3  4  5  6  7  8  9  10  [11]  12  13  14  15  ...