Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 726. ARM 플랫폼용 Visual C++ 리눅스 프로젝트 빌드 [링크 복사], [링크+제목 복사],
조회: 6064
글쓴 사람
정성태 (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)
13287정성태3/16/202311613Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/202312025Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/202311408Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법 [2]파일 다운로드1
13284정성태3/13/202311280Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/202310106오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/202310499Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/202311149Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/202312633개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/202312091오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
13278정성태3/8/202311891개발 환경 구성: 669. WSL 2의 (init이 아닌) systemd 지원 [1]
13277정성태3/6/202313187개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/202312762.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어 [1]
13275정성태3/3/202312675.NET Framework: 2101. C# 11의 ref 필드 설명
13274정성태3/2/202311949.NET Framework: 2100. C# - ref 필드로 ref struct 타입을 허용하지 않는 이유
13273정성태2/28/202310968.NET Framework: 2099. C# - 관리 포인터로서의 ref 예약어 의미
13272정성태2/27/202311853오류 유형: 850. SSMS - mdf 파일을 Attach 시킬 때 Operating system error 5: "5(Access is denied.)" 에러
13271정성태2/25/202311659오류 유형: 849. Sql Server Configuration Manager가 시작 메뉴에 없는 경우
13270정성태2/24/202310947.NET Framework: 2098. dotnet build에 /p 옵션을 적용 시 유의점
13269정성태2/23/202312319스크립트: 46. 파이썬 - uvicorn의 콘솔 출력을 UDP로 전송
13268정성태2/22/202312760개발 환경 구성: 667. WSL 2 내부에서 열고 있는 UDP 서버를 호스트 측에서 접속하는 방법
13267정성태2/21/202313098.NET Framework: 2097. C# - 비동기 소켓 사용 시 메모리 해제가 finalizer 단계에서 발생하는 사례파일 다운로드1
13266정성태2/20/202312407오류 유형: 848. .NET Core/5+ - Process terminated. Couldn't find a valid ICU package installed on the system
13265정성태2/18/202312816.NET Framework: 2096. .NET Core/5+ - PublishSingleFile 유형에 대한 runtimeconfig.json 설정
13264정성태2/17/202314787스크립트: 45. 파이썬 - uvicorn 사용자 정의 Logger 작성
13263정성태2/16/202312095개발 환경 구성: 666. 최신 버전의 ilasm.exe/ildasm.exe 사용하는 방법
13262정성태2/15/202313479디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
... 16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  ...