tonypai
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
1
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 如何用現代的手段,編譯石器時代的原始碼? ###### tags: `misc` 分成三個段落: - 構建環境 - 排除問題 - 部署服務 ## 構建環境 棄用 CentOS 改用 Debian 來運行服務端,Debian 相對將要停止維護的 CentOS 而言是更好的選擇,而且常聽到的 Ubuntu 也是其分支,版本則採用 buster,也就是當前最穩定的版本,加上編譯 C 所需要的套件,於是我直接在 Dockerhub 上找封裝好的 Docker Image 來用,我們可以從其 [Dockerfile](https://github.com/silkeh/docker-clang/blob/master/3.3.Dockerfile)(定義檔)中知道裝了哪些套件。 資料庫部分,由於 MySQL 已經被 Oracle 收購,開源社群轉而投向保持著和 MySQL 有高度相容性且更為開放的 MariaDB 的懷抱,也因此我們直接選用 MariaDB 作為資料庫引擎。 ## 排除問題 首先我遇到的第一個問題,就是在非 c99 標準之下不允許我們在 for loop 中宣告變數。 ```c for (int i=1;i<10;i++) { // error int i; for (i=1;i<10;i++) { // ok ``` 雖然直接改 Code 就可以解決,但是因為要改的太多,所以選擇直接在 CMake 設定檔中加上 flag,就可以啟動 c99 標準而順利編譯。👉 [參考連結](https://stackoverflow.com/a/30564223) **CMakeLists.txt** ```cmake macro(use_c99) if (CMAKE_VERSION VERSION_LESS "3.1") if (CMAKE_C_COMPILER_ID STREQUAL "GNU") set (CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") endif () else () set (CMAKE_C_STANDARD 99) endif () endmacro(use_c99) ``` 第二個問題就是當我們使用 MariaDB 的時候,在編譯階段編譯器會告訴我們找不到 `mysql/mysql.h` ,這很明顯是因為我們換了資料庫,所以相應的函式庫也得調整。 **saac/src/sasql.c** ```c #include <mysql/mysql.h> // error #include <mariadb/mysql.h> // ok ``` **saac/CMakeLists.txt** ```c target_link_libraries(saac mysqlclient) // error target_link_libraries(saac mariadbclient) // ok ``` ## 部署服務 最後就是把服務串連起來,服務端的架設就算完成了,這邊我們寫了 docker-compose.yml(定義檔),簡單來說就是把服務的 Port、關聯性以及設定都寫進定義檔中,而這種將系統架構用 YAML 或 Code 的方式描述,就是所謂的 Infrastracture as code(IaC)。 這樣做的好處就是只要一個指令就可以完整的啟動服務端,因為在透過定義檔啟動後,事情都會交由工具本身去做,這邊是利用 Docker Compose 來完成。 **docker-compose.yml** ```yaml version: '3.5' services: net: image: alpine:3.7 network_mode: bridge ports: - 9065:9065 command: tail -f /dev/null restart: always gmsv: image: tonypai/sa25_gmsv network_mode: service:net depends_on: - saac command: /bin/bash -i ./wait-for-it.sh 127.0.0.1:9300 -- ./gmsv saac: image: tonypai/sa25_saac network_mode: service:net depends_on: - db command: /bin/bash -i ./wait-for-it.sh 127.0.0.1:3306 -- ./saac db: image: mariadb:10 network_mode: service:net volumes: - db-data:/var/lib/mysql restart: always environment: MYSQL_DATABASE: sa MYSQL_USER: user MYSQL_PASSWORD: pass MYSQL_ROOT_PASSWORD: admin volumes: db-data: ``` ## 結論 如果大家想玩看看的話,先去下載 [Docker Desktop](https://www.docker.com/get-started) 把 Docker 環境建置起來,建立 `docker-compose.yml` 定義檔。 然後下一行指令服務端就啟動完成了。 ```sh docker-compose up gmsv saac ``` 🎬 [展示影片](https://drive.google.com/file/d/1w8BnFVRqTQwCGhg2dUa_KWKqgYyBTGRe/view?usp=sharing) 👉 [專案下載](https://drive.google.com/file/d/1RQVINIhBcDb4ow3cR4kYHfZQ0BI2uuSe/view?usp=sharing) (題外話:我手上的 2.5 版似乎有 bug,耐久力/氣力恢復藥沒辦法使用 QQ)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully