2016년 6월 19일 일요일

SystemC on Windows (using Bash on Windows)

1. Normally, SystemC uses dynamically linked library. However, it does not work (yet) in Bash on Windows:
The error message goes: "error while loading shared libraries: libsystemc-2.3.1.so: cannot enable executable stack as shared object requires: Invalid argument".

Note that I've already set the environment variable, LD_LIBRARY_PATH, to the directory where SystemC library resides as below:

2. A workaround is to use static-linking:
Note the flags used in the linking command:
-Wl, -Bstatic -lsystemc -Wl, -Bdynamic -pthread

SystemC를 Ubuntu에서 이용하는 방법 (Hello world program)

0. 가정: SystemC 설치 방법을 설명한 이 글에서와 같이, SystemC는 "$HOME/sysc"에 설치되어 있음을 가정.

1. SystemC hello world program의 code (main.cpp):
#include <iostream>

#include "systemc.h"

using namespace std;

int sc_main(int argc, char *argv[]) {
  cout << "Hello, world!" << endl;
  return 0;
}

2. "LD_LIBRARY_PATH" 환경 변수 설정을 위해 "$HOME/.bashrc"에 다음을 추가:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/sysc/lib-linux64
export LD_LIBRARY_PATH

3. Compile을 위한 command:
g++ -o main -I$HOME/sysc/include -L$HOME/sysc/lib-linux64 main.cpp -lsystemc

4. 다음과 같이 실행됨:

SystemC를 Ubuntu에 설치하는 방법

1. Accellera website (http://accellera.org/)에서 "Downloads" → "Accellera Standards" 선택.

2. "Available Accellera Systems Initiative Standards" 화면에서 "SystemC" 선택.

3. "SystemC" 화면에서 "Core SystemC Language and Examples" 선택.

4. "SystemC Open Source License Agreement" 화면이 나오는데, "I accept the SystemC Open Source License" 선택.

5. 다시 한 번 "SystemC" 화면이 나오는데, 여기서 다시 "Core SystemC Language and Examples" 선택.

6. "systemc-2.3.1.tgz" file을 download.

7. Download된 file을, 다음 명령으로 압축을 푼다.
tar xvzf systemc-2.3.1.tgz

8. Build (configure).
  1. 압축이 풀리면 "systemc-2.3.1"라는 directory가 생기는데, "cd systemc-2.3.1"해서 그 안으로 들어간다.
  2. Build를 위해 "mkdir build", "mkdir ~/sysc"를 한다 ("build" directory 에서 build를 하고, "~/sysc" directory에 설치를 할 것이다). 
  3. "cd build" 하여 "build" directory에 들어간 후, 다음 명령어로 configure (build를 위한 사전 작업)를 한다.
    ../configure --prefix=$HOME/sysc

9. Build (make; make install)
  1. "make"로 build 한 다음..
  2. "make install"로 install 한다. 

10. 다음과 같이, "~/sysc"에 SystemC가 설치된 것을 알 수 있다.

11. 설치된 SystemC의 기본적인 사용법에 관해서는 이 글을 참고. 

2016년 6월 12일 일요일

Bash on Windows 설치 방법

1. Windows 10의 Insider Preview build를 이용하기 위해서 다음을 한다.

1-1. Windows 시작 button → "설정" 선택:

1-2. "업데이트 및 복구"를 선택:

1-3. "Windows 업데이트" → "고급 옵션" 선택:

1-4. "Insider Preview 빌드 가져오기"의 "시작"을 선택:

1-5. "Insider Preview 빌드" 창에서 "등록"을 선택:

1-6. https://insider.windows.com/에 자동으로 연결 되는데, "시작하기"를 선택:

1-7. "이 계약 조건에 동의합니다(필수)."에 check한 후 "제출" 선택:

1-8. Web page를 닫는다:

1-9. 앞의 "설정" 창에서 "다음 단계"를 선택한다:

1-10. 확인을 위한 창들이 뜨는데, "다음", "확인"을 선택:

1-11. Reboot을 위한 창에서 "지금 다시 시작"을 선택:

1-12. "1-2" 단계와 같이 "설정" → "업데이트 및 복구" 창에서 "개발자용" → "개발자 모드"를 선택:

1-13. 확인을 위한 창이 뜨는데, "예"를 선택해서 개발자 모드를 켠다:

1-14. "1-3"의 "고급 옵션" 창에서, 아래와 같이 "Insider 수준"을 "초기"로 맞춘다 (선택 bar를 가장 오른쪽으로):

1-15. 이제 준비 완료. Windows 10 Insider Preview build는 Windows update로 받는 것임. 위의 설정을 적용하자 마자는 아래와 같이 "업데이트 확인"해도 Windows 10 Insider Preview build가 검지되지 않음 (나는 설정 다음 날에야 가능했음):

1-16. 아래 그림과 같이 "Windows 10 Insider Preview 14361"이 update되는 걸 확인해야 함 (아마도 14361보다 더 큰 version도 괜찮을 것임):

1-17. Update가 끝나면 "지금 다시 시작"을 선택해서 reboot:

1-18. Reboot이 끝나면 바탕화면 오른쪽 아래에 다음 그림과 같이 "평가본입니다."라고 나옴:

2. Bash on Windows를 활성화 하기 위해서 다음을 한다.

2-1. "제어판" → "프로그램" 선택:

2-2. "Windows 기능 켜기/끄기" 선택:

2-3. "Windows 기능" 창에서 "Linux용 Windows 하위 시스템(베타)"를 check한 후에 "확인"을 선택 (참고로 영어로는 "Windows Subsystem for Linux (Beta)" 임):

2-4. 다음 창이 뜨는데 "다시 시작"을 선택해서 reboot:

2-5. 완성.

3. Bash를 실행시켜 보려면 작업표시줄에 "bash"를 입력하고 Enter:



3-1. Bash를 처음 실행하면 다음과 같이 "동의", "사용자 이름", "암호 입력"을 진행한다 (글이 조금 깨지는데 beta니깐 이해하자):

3-2. 다음과 같이 bash가 Windows command-line처럼 실행된다:

참고:
  1. https://insights.ubuntu.com/2016/04/14/howto-ubuntu-on-windows-2/ 

2016년 6월 6일 월요일

Google blog (Blogger) - Source code 예쁘게 올리기

요약: Google Code Prettify (https://github.com/google/code-prettify)를 이용한다.

1. Google blog에 login 한 상태로 오른쪽 위의 "디자인"을 click.

2. "템플릿" → "HTML 편집" 선택.

3. 오른쪽의 code에서 "</head>" 앞에 다음과 같이 입력하고 "템플릿 저장"을 click.
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

4. 완성. Blog에 글을 쓸 때, "HTML"을 선택하고 다음과 같이 "<pre class="prettyprint">"와 "</pre>" 사이에 source code를 넣으면 된다.
<pre class="prettyprint">int main(int argc, char *argv[]) {
  return 0;
}</pre>

5. 글을 게시하면 다음과 같이 source code가 예쁘게 나타남.
int main(int argc, char *argv[]) {
  return 0;
}

※ HTML이 특별하게 취급하는 문자들은 다음과 같이 바꿔줘야 (escape해야) 함.
fromto
&&amp;
<&lt;
>&gt;
"&quot;

이를 위해 나는 다음 C++ program을 만들어 사용:
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

void ReplaceAll(string &str, char from, string to) {
  size_t pos = 0;
  while (true) {
    pos = str.find(from, pos);
    if (pos == string::npos) break;

    str.replace(pos, 1, to);
    pos += to.length();
  }
}

int main(int argc, char *argv[]) {
  if (argc != 2) {
    cerr << "usage: " << argv[0] << " [input file]" << endl;
    exit(1);
  }

  string ifname = argv[1];
  ifstream ifile(ifname);
  if (!ifile.is_open()) {
    cerr << "cannot open: " << ifname << endl;
    exit(1);
  }

  string ofname = ifname.insert(ifname.length() - 4, ".pre");
  ofstream ofile(ofname);
  if (!ofile.is_open()) {
    cerr << "cannot open: " << ofname << endl;
    exit(1);
  }

  string line;
  while (getline(ifile, line)) {
    ReplaceAll(line, '&', "&amp;");
    ReplaceAll(line, '<', "&lt;");
    ReplaceAll(line, '>', "&gt;");
    ReplaceAll(line, '\"', "&quot;");

    ofile << line << endl;
  }

  ifile.close();
  ofile.close();
}

참고:
  1. https://www.sitepoint.com/everything-need-know-html-pre-element/

2016년 6월 4일 토요일

Ubuntu download 과정

1. Ubuntu website 방문 (http://www.ubuntu.com/) 후 "Download" → "Desktop" 선택.

2. 다음 화면에서 "Download" 선택.

3. Ubuntu 개발에의 기부 여부를 묻는 "Contribute to Ubuntu" 화면이 나오는데, "Not now, take me to the download"를 선택하면 기부 없이 진행할 수 있다.

4. 자동으로 download가 시작되고, 끝나면 "폴더 열기"를 선택한다.

5. Download된 iso file을 확인한다.