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

비밀번호

댓글 작성자
 




... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12712정성태7/15/202116108개발 환경 구성: 579. Azure - 리눅스 호스팅의 Site Extension 제작 방법
12711정성태7/15/202116130개발 환경 구성: 578. Azure - Java Web App Service를 위한 Site Extension 제작 방법
12710정성태7/15/202118752개발 환경 구성: 577. MQTT - emqx.io 서비스 소개
12709정성태7/14/202114284Linux: 42. 실행 중인 docker 컨테이너에 대한 구동 시점의 docker run 명령어를 확인하는 방법
12708정성태7/14/202118492Linux: 41. 리눅스 환경에서 디스크 용량 부족 시 원인 분석 방법
12707정성태7/14/202185727오류 유형: 734. MySQL - Authentication method 'caching_sha2_password' not supported by any of the available plugins.
12706정성태7/14/202116911.NET Framework: 1076. C# - AsyncLocal 기능을 CallContext만으로 구현하는 방법 [2]파일 다운로드1
12705정성태7/13/202117295VS.NET IDE: 168. x64 DLL 프로젝트의 컨트롤이 Visual Studio의 Designer에서 보이지 않는 문제 - 두 번째 이야기
12704정성태7/12/202116087개발 환경 구성: 576. Azure VM의 서비스를 Azure Web App Service에서만 접근하도록 NSG 설정을 제한하는 방법
12703정성태7/11/202121465개발 환경 구성: 575. Azure VM에 (ICMP) ping을 허용하는 방법
12702정성태7/11/202117170오류 유형: 733. TaskScheduler에 등록된 wacs.exe의 Let's Encrypt 인증서 업데이트 문제
12701정성태7/9/202116721.NET Framework: 1075. C# - ThreadPool의 스레드는 반환 시 ThreadStatic과 AsyncLocal 값이 초기화 될까요?파일 다운로드1
12700정성태7/8/202117160.NET Framework: 1074. RuntimeType의 메모리 누수? [1]
12699정성태7/8/202115694VS.NET IDE: 167. Visual Studio 디버깅 중 GC Heap 상태를 보여주는 "Show Diagnostic Tools" 메뉴 사용법
12698정성태7/7/202119942오류 유형: 732. Windows 11 업데이트 시 3% 또는 0%에서 다운로드가 멈춘 경우
12697정성태7/7/202115011개발 환경 구성: 574. Windows 11 (Insider Preview) 설치하는 방법
12696정성태7/6/202115969VC++: 146. 운영체제의 스레드 문맥 교환(Context Switch)을 유사하게 구현하는 방법파일 다운로드2
12695정성태7/3/202115997VC++: 145. C 언어의 setjmp/longjmp 기능을 Thread Context를 이용해 유사하게 구현하는 방법파일 다운로드1
12694정성태7/2/202117936Java: 24. Azure - Spring Boot 앱을 Java SE(Embedded Web Server)로 호스팅 시 로그 파일 남기는 방법 [1]
12693정성태6/30/202114879오류 유형: 731. Azure Web App Site Extension - Failed to install web app extension [...]. {1}
12692정성태6/30/202115360디버깅 기술: 180. Azure - Web App의 비정상 종료 시 남겨지는 로그 확인
12691정성태6/30/202115617개발 환경 구성: 573. 테스트 용도이지만 테스트에 적합하지 않은 Azure D1 공유(shared) 요금제
12690정성태6/28/202116629Java: 23. Azure - 자바(Java)로 만드는 Web App Service - Tomcat 호스팅
12689정성태6/25/202118329오류 유형: 730. Windows Forms 디자이너 - The class Form1 can be designed, but is not the first class in the file. [1]
12688정성태6/24/202117653.NET Framework: 1073. C# - JSON 역/직렬화 시 리플렉션 손실을 없애는 JsonSrcGen [2]파일 다운로드1
12687정성태6/22/202114970오류 유형: 729. Invalid data: Invalid artifact, java se app service only supports .jar artifact
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...