kerwin
    • 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
    • Invite by email
      Invitee

      This note has no invitees

    • 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
    • Note Insights
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
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
  • Invite by email
    Invitee

    This note has no invitees

  • 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 在OSX Catalina 上安裝 Allegro 5 因為在升級上osx caralina 以後,所有32-bit的程式都不能夠再被系統執行,但是在各位寫final project 的時候新的Allegro還沒辦法被套件管理器正確支援。 因此我們今天就要來教大家如何在自己的電腦上 build Allegro 5.2.6。 ## 環境準備 首先你需要安裝Homebrew Homebrew 套件管理器介紹 https://brew.sh/index_zh-tw 一、收先我們打開 Mac 的終端機輸入: ``` bash $ /usr/bin/ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) ``` 他就會開始自己安裝了。 安裝完以後你可以接著輸入: ``` bash $ brew --version ``` 就會像下面一樣看到,brew 的版本 ![](https://i.imgur.com/sDfDFLT.png) **一些基本得操作** 1. ``brew install packahe_name`` -- 安裝套件 2. ``brew search`` -- 搜尋需要的套件 ## 正式開始安裝 ### 相依套件 收先在開始自己 build 以前我們要先安裝 Allegro 5 的相依套件,那我們一樣用brew 來安裝 ```bash $ brew install dumb flac freetype libogg libvorbis opusfile physfs theora webp git cmake gcc ``` 安裝完成以後我們就可以去Allegro 的 github page 下載檔案了~ https://github.com/liballeg/allegro5 我們打開終端機輸入: ```bash $ git clone https://github.com/liballeg/allegro5.git && cd allegro5 ``` 你會發現我們已經在 allegro5 這個資料夾內了 接下來我們在這邊新增一個編譯用的資料夾,通常來說我們會做這樣一個資料夾來讓編譯的檔案都放在一起,這樣可以有效的跟原本的source code 隔離,如果我們想要清理環境,就只要刪除build 這個資料夾就好了 ```bash $ mkdir build $ cd build ``` ### 編譯 接下來進入編譯過程,首先要做得事情就是 configure Allegro ```bash $ cmake .. ``` ![](https://i.imgur.com/a1vRn1S.png) configure 完成後就可以開始編譯拉,這裏會用到 make 指令至於這個指令工作的機制稍後會提到 ```bash $ make ``` ![](https://i.imgur.com/5Jh6EgC.jpg) ![](https://i.imgur.com/0gGTP7Z.jpg) build 完以後我們要來安裝他。 ```bash $ sudo make install ``` 這時候需要輸入你得密碼 :::warning 注意! 密碼不會出現在螢幕上 ::: ![](https://i.imgur.com/W5SUrbq.jpg) 他會把需要得檔案裝在 ``/usr/local/lib`` 裡面,header檔則是在 ``/usr/local/include/``底下。 ## 在 Mac 上使用 Allegro 5 原本在 Xcode 上面按下一個按鈕就可以編譯這種美好的事情現在不可能拉。 但是還是有好用的IDE可以用得~ 那就是 VScode 拉 ![](https://i.imgur.com/94EuMZe.png =200x200) 至於要怎麼裝就請到官網去看 https://code.visualstudio.com/ 然後我們需要安裝C/C++的插件 按下左邊這個按鈕 ![](https://i.imgur.com/pF8qOwe.png) 搜尋 C/C++,點擊安裝 ![](https://i.imgur.com/nfoemtD.jpg) 介面看起來大概像這個子~ ![](https://i.imgur.com/g3SGy4l.jpg) 接下來我們要來講解編譯的事情,你能夠用 Allegro 這個 libiarrays 的內容來寫扣是且執行是因為你在編譯的時候,編譯器可以找到相對印的函數來把你的程式轉乘成電腦看得懂的語言,這是在 linker 時期完成的(有興趣得同學可以自己來這邊了解編譯器的運作過程 https://medium.com/@aesl/understanding-compilers-for-humans-ba970e045877)。 其實不只是 Allegro ,還記得每次寫扣前都要載入的標頭檔嗎? 你可以使用``printf``這些函數的原因也是因為如此。 C Complier 之所以可以幫你翻譯``printf``是因為他認得 ``printf``這個東西是在 stdio.h 這個函式庫裡被定義的。 但是Complier 並不認得 allegro/allegro.h 這個函式庫,那這時候我們就要手動告訴他,因此我們需要一個工具。 ### pkg-config pkg-config 是一個在原始碼編譯時查詢已安裝的庫的使用介面的電腦工具軟體。pkg-config原本是設計用於Linux的,但現在在各個版本的BSD、windows、Mac OS X和Solaris上都有著可用的版本。 它輸出已安裝的庫的相關資訊,包括: - C/C++編譯器需要的輸入參數 - 連結器需要的輸入參數 - 已安裝軟體包的版本資訊 一如往常的,我們先來安裝他: ```bash $ brew install pkg-config ``` 當你輸入下面這個指令``pkg-config --libs allegro-5``的時候你就會發現,那吐回給你一個路徑,這就是 Allegro 的 object file 和 header file 擺放的地方。 ```bash $ pkg-config --libs allegro-5 -L/usr/local/lib -lallegro ``` 那接下來請各位同學用 vscode 打開助教給的 template 利用終端機進入,task_5 這個資料夾,我們來實際編譯看看 task_5_ans.c這個檔案。 ```bash $ gcc task_5_ans.c -o task_5.out $(pkg-config allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5 allegro_dialog-5 allegro_primitives-5 allegro_audio-5 allegro_acodec-5 --libs --cflags) -lallegro -lallegro_main ``` 解釋一下 - gcc 是調用 complier 的指令。 - 接著的是當案名稱。 - -o 後面的是編譯出來的執行檔名稱,不加的話會是 a.out。 - 後面的一長串是編譯的flag 這邊是調用pkg-config 來把allegro 的路徑告訴編譯器讓他認得這些函數。 那接下來我們就可以執行他拉~ ```bash $ ./task_5.out ``` 如果成功的話應該會看到,類似像這樣的畫面 ![](https://i.imgur.com/ZXKcbkz.png) 到此為止你就成功了~ 還沒完,你不覺得每次編譯都要打這些東西很麻煩?有沒有更好的方法來簡化編譯得過程啊~~ 有的有的,請繼續往下看..... ### Makefile 網路上有不少教學例如 https://ccckmit.gitbooks.io/lowlevelc/content/makefile.html 我相信這對同學來說有點難,不過沒關係能夠理解就理解,如果不行就照抄我給的範例。 但是還是希望你把下面得內容看完,因為這樣你才知道要改什麼內容。 以下是這次 Final project 給的 makefile ```cpp= ALLEGRO_LIBRARIES := allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5 allegro_dialog-5 allegro_primitives-5 allegro_audio-5 allegro_acodec-5 ALLEGRO_FLAGS := $(shell pkg-config --cflags --libs $(ALLEGRO_LIBRARIES)) -lallegro -lallegro_main CC := gcc OUT:= task_5.out MAIN:= task_5_ans.o all: $(MAIN) $(CC) -o $(OUT) $(MAIN) $(ALLEGRO_FLAGS) clean: rm $(OUT) ``` 可以觀察到,我們把 ALLEGRO_LIBRARIES , ALLEGRO_FLAGS 就是拿來定義編譯得參數 比較需要注意的是,MAIN 和 OUT 這個參數。他們分邊定義了.c 檔的名稱以及輸出檔案的名稱。就根據你現在的檔案名稱來更改,其餘的東西都不用動。 要用的時候只要打 ```bash $ make ``` 就可以了 那如果想要刪掉最後輸出的執行檔的話,只要打 ```bash $ make clean ``` 就好了~~~ 希望各位同學可以順利的寫完 final project ### 程設二的部分 Makefile ```cpp= CC := g++ CFLAGS := -Wall -std=c++17 -O2 -v ALLEGRO_LIBRARIES := allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5 allegro_dialog-5 allegro_primitives-5 allegro_audio-5 allegro_acodec-5 ALLEGRO_FLAGS := $(shell pkg-config --cflags --libs $(ALLEGRO_LIBRARIES)) -lallegro -lallegro_main OUT:= game SOURCE = Main.cpp Attack.cpp Circle.cpp GameWindow.cpp global.cpp Level.cpp Menu.cpp Monster.cpp Slider.cpp Tower.cpp OBJ = Main.o Attack.o Circle.o GameWindow.o global.o Level.o Menu.o Monster.o Slider.o Tower.o all: $(CC) -c -g $(CFLAGS) $(SOURCE) $(ALLEGRO_FLAGS) $(CC) $(CFLAGS) -o $(OUT) $(OBJ) $(ALLEGRO_FLAGS) rm $(OBJ) .PHONY:clean clean: rm $(OUT) ```

    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