Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 336. 윈도우 10 Bash 쉘에서 C++ 컴파일하는 방법 [링크 복사], [링크+제목 복사],
조회: 20009
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

윈도우 10 Bash 쉘에서 C++ 컴파일하는 방법

이 글은 다음의 내용을 정리한 것입니다.

Compile C++ program with g++ compiler on Bash on Ubuntu on Windows 10
; https://www.developerinsider.in/compile-cpp-program-with-gplusplus-compiler-on-bash-on-ubuntu-on-windows-10/

따라서 다음과 같이 설치해 주고,

$ sudo apt-get install g++

정상적으로 설치되었는지 확인 후,

$ g++ --version

간단하게 nano 편집기를 이용해 hello.cpp 파일을 만들어,

$ nano hello.cpp

내용을 채운 후,

#include <iostream>

using namespace std;

int main()
{
  cout<<"hello world!!\n";
  return 0;
}

컴파일 합니다.

g++ hello.cpp -o hello

실행은 이렇게!

$ ls
hello  hello.cpp

$ ./hello
hello world!!




생성한 파일을 라즈베리 파이에 samba를 이용해 올려놓고 실행하니 다음과 같은 오류가 뜹니다.

$ ./hello
-bash: ./hello: cannot execute binary file: Exec format error

왜냐하면 빌드된 파일의 플랫폼이 다르기 때문입니다.

$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=7f524ac8669192ab27c9fcbb5f9e0028933f68a4, not stripped

Raspberry Pi는 ARM CPU인데, 윈도우의 bash shell에서 빌드한 것은 x86-64 용이므로 "Exec format error"가 당연합니다. 이번에는 그냥 라즈베리 파이 내에서 컴파일을 시켰습니다. ^^

$ g++ hello.cpp -o hello

$ ls
hello  hello.cpp

$ ./hello
hello world!!





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







[최초 등록일: ]
[최종 수정일: 11/15/2017]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 91  92  93  94  [95]  96  97  98  99  100  101  102  103  104  105  ...
NoWriterDateCnt.TitleFile(s)
11265정성태8/10/201741386기타: 66. 도서: 시작하세요! C# 7.1 프로그래밍: 기본 문법부터 실전 예제까지 [11]
11264정성태8/9/201715354오류 유형: 414. UWP app을 signtool.exe로 서명 시 0x8007000b 오류 발생
11263정성태8/9/201712423오류 유형: 413. The C# project "..." is targeting ".NETFramework, Version=v4.0", which is not installed on this machine. [3]
11262정성태8/5/201711589오류 유형: 412. windbg - SOS does not support the current target architecture. [3]
11261정성태8/4/201713731디버깅 기술: 91. windbg - 풀 덤프 파일로부터 강력한 이름의 어셈블리 추출 후 사용하는 방법
11260정성태8/3/201712068.NET Framework: 670. C# - 실행 파일로부터 공개키를 추출하는 방법
11259정성태8/2/201711683.NET Framework: 669. 지연 서명된 어셈블리를 sn.exe -Vr 등록 없이 사용하는 방법
11258정성태8/1/201712141.NET Framework: 668. 지연 서명된 DLL과 서명된 DLL의 차이점파일 다운로드1
11257정성태7/31/201712735.NET Framework: 667. bypassTrustedAppStrongNames 옵션 설명파일 다운로드1
11256정성태7/25/201713776디버깅 기술: 90. windbg의 lm 명령으로 보이지 않는 .NET 4.0 ClassLibrary를 명시적으로 로드하는 방법 [1]
11255정성태7/18/201716330디버깅 기술: 89. Win32 Debug CRT Heap Internals의 0xBAADF00D 표시 재현 [1]파일 다운로드3
11254정성태7/17/201713009개발 환경 구성: 322. "Visual Studio Emulator for Android" 에뮬레이터를 "Android Studio"와 함께 쓰는 방법
11253정성태7/17/201712966Math: 21. "Coding the Matrix" 문제 2.5.1 풀이 [1]파일 다운로드1
11252정성태7/13/201712428오류 유형: 411. RTVS 또는 PTVS 실행 시 Could not load type 'Microsoft.VisualStudio.InteractiveWindow.Shell.IVsInteractiveWindowFactory2'
11251정성태7/13/201710961디버깅 기술: 88. windbg 분석 - webengine4.dll의 MgdExplicitFlush에서 발생한 System.AccessViolationException의 crash 문제 (2)
11250정성태7/13/201714012디버깅 기술: 87. windbg 분석 - webengine4.dll의 MgdExplicitFlush에서 발생한 System.AccessViolationException의 crash 문제 [1]
11249정성태7/12/201711995오류 유형: 410. LoadLibrary("[...].dll") failed - The specified procedure could not be found.
11248정성태7/12/201718410오류 유형: 409. pip install pefile - 'cp949' codec can't decode byte 0xe2 in position 208687: illegal multibyte sequence
11247정성태7/12/201712633오류 유형: 408. SqlConnection 객체 생성 시 무한 대기 문제파일 다운로드1
11246정성태7/11/201711726VS.NET IDE: 118. Visual Studio - 다중 폴더에 포함된 파일들에 대한 "Copy to Output Directory"를 한 번에 설정하는 방법
11245정성태7/10/201716755개발 환경 구성: 321. Visual Studio Emulator for Android 소개 [2]
11244정성태7/10/201715749오류 유형: 407. Visual Studio에서 ASP.NET Core 실행할 때 dotnet.exe 프로세스의 -532462766 오류 발생 [1]
11243정성태7/10/201712669.NET Framework: 666. dotnet.exe - 윈도우 운영체제에서의 .NET Core 버전 찾기 규칙
11242정성태7/8/201713407제니퍼 .NET: 27. 제니퍼 닷넷 적용 사례 (7) - 노후된 스토리지 장비로 인한 웹 서비스 Hang (멈춤) 현상
11241정성태7/8/201712406오류 유형: 406. Xamarin 빌드 에러 XA5209, APT0000
11240정성태7/7/201714840.NET Framework: 665. ClickOnce를 웹 브라우저를 이용하지 않고 쿼리 문자열을 전달하면서 실행하는 방법 [3]파일 다운로드1
... 91  92  93  94  [95]  96  97  98  99  100  101  102  103  104  105  ...