Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 726. ARM 플랫폼용 Visual C++ 리눅스 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 6060
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  26  27  [28]  29  30  ...
NoWriterDateCnt.TitleFile(s)
13237정성태1/30/202314269.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
13236정성태1/29/202313036개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
13235정성태1/29/202312502개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
13234정성태1/28/202314903개발 환경 구성: 661. dnSpy를 이용해 소스 코드가 없는 .NET 어셈블리의 코드를 변경하는 방법 [1]
13233정성태1/28/202316120오류 유형: 840. C# - WebClient로 https 호출 시 "The request was aborted: Could not create SSL/TLS secure channel" 예외 발생
13232정성태1/27/202312023스크립트: 43. uwsgi의 --processes와 --threads 옵션
13231정성태1/27/202311236오류 유형: 839. python - TypeError: '...' object is not callable
13230정성태1/26/202312005개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
13229정성태1/25/202313871.NET Framework: 2090. C# - UDP Datagram의 최대 크기
13228정성태1/24/202314417.NET Framework: 2089. C# - WMI 논리 디스크가 속한 물리 디스크의 정보를 얻는 방법 [2]파일 다운로드1
13227정성태1/23/202313322개발 환경 구성: 659. Windows - IP MTU 값을 바꿀 수 있을까요? [1]
13226정성태1/23/202312294.NET Framework: 2088. .NET 5부터 지원하는 GetRawSocketOption 사용 시 주의할 점
13225정성태1/21/202311620개발 환경 구성: 658. Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
13224정성태1/21/202312122Windows: 221. Windows - Private/Public/Domain이 아닌 네트워크 어댑터 단위로 방화벽을 on/off하는 방법
13223정성태1/20/202312061오류 유형: 838. RDP 연결 오류 - The two computers couldn't connect in the amount of time allotted
13222정성태1/20/202311897개발 환경 구성: 657. WSL - DockerDesktop.vhdx 파일 위치를 옮기는 방법
13221정성태1/19/202312103Linux: 57. C# - 리눅스 프로세스 메모리 정보파일 다운로드1
13220정성태1/19/202311730오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/202311380Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/202311250VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/202311971디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/202311892디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
13215정성태1/11/202314909Linux: 56. 리눅스 - /proc/pid/stat 정보를 이용해 프로세스의 CPU 사용량 구하는 방법 [1]
13214정성태1/10/202313775.NET Framework: 2087. .NET 6부터 SourceGenerator와 통합된 System.Text.Json [1]파일 다운로드1
13213정성태1/9/202312159오류 유형: 836. docker 이미지 빌드 시 "RUN apt install ..." 명령어가 실패하는 이유
13212정성태1/8/202313542기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
... 16  17  18  19  20  21  22  23  24  25  26  27  [28]  29  30  ...