Sean Yih
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # SDL2: 安裝 ###### tags: `SDL` ## 前言 這篇文章獻給所有想靠著網站LazyFoo學習SDL,卻發現下載下來的檔案都打不開。和所有覺得安裝SDL2真的鳥到爆卻因為學分不得不想辦法安裝的人們。**~~<–本人目前在這~~** 因為對於每次都要重新建project和輸入一堆參數(大部分教學的方法)感到厭煩,所以決定直接system-wide安裝,一勞永逸。以下兩種方法都會提供。 注意,以下方法適用的系統是: **Windows(x64) + DevC++** 任何不是使用這種配置的用戶,你可能得另請高明教你安裝…… ## 下載 首先下載SDL和所有相關的資源包。 - 官網: [https://github.com/libsdl-org/SDL/releases/] 下載、解壓完成後,你會得到一堆資料夾們,這時候就是你決定安裝方式的時候了! ## Case 1: Global Compiler Settings ### 優缺點 - 優點: 不用一直建立project,每次建立都要重新輸入路徑等等。 - 缺點: 編譯其他不用SDL的程式碼時會浪費一些資源(幾乎無感)。 結論: 短時間內會大量使用SDL的話就用吧! ### Step 1: 將資源包找個地方放 不如就放在C:/吧! 最好找。請將所有資源包都放在同一個路徑底下,**不要拆開資料夾內的東西!!!**,完成後你的資料夾們應該長得像: ``` C:/ ├─ SDL2-2.24.2/ ├─ SDL2_image-2.6.2/ ⋮ ``` C:/可以換成任何你想要放的地方,暫且稱作<path>。那麼之後遇到C:/的地方都要用<path>取代掉。例如: ``` let <path> = C:\Program Files(x86) C:\SDL2-2.24.2\x86_64-w64-mingw32\lib -> C:\Program Files(x86)\SDL2-2.24.2\x86_64-w64-mingw32\lib ``` ### Step 2: 設定Compiler 我們有三個部分要設定,首先是函式庫路徑,請點擊Tools > Compiler Options,選單選到Directories -> Libraries **逐行**輸入以下路徑到視窗底部的輸入框,完成後**按Add**: ``` C:\SDL2-2.24.2\x86_64-w64-mingw32\lib C:\SDL_bgi-2.6.0\bin\Mingw64 C:\SDL2_image-2.6.2\x86_64-w64-mingw32\lib C:\SDL2_mixer-2.6.2\x86_64-w64-mingw32\lib C:\SDL2_ttf-2.20.1\x86_64-w64-mingw32\lib C:\SDL2_net-2.2.0\x86_64-w64-mingw32\lib ``` 全部完成後,一樣在上方選單,選到Directories -> C++ Includes **逐行**輸入以下路徑到視窗底部的輸入框,完成後**按Add**: ``` C:\SDL2-2.24.2\x86_64-w64-mingw32\include\SDL2 C:\SDL_bgi-2.6.0\src C:\SDL2_mixer-2.6.2\x86_64-w64-mingw32\include C:\SDL2_image-2.6.2\x86_64-w64-mingw32\include C:\SDL2_ttf-2.20.1\x86_64-w64-mingw32\include C:\SDL2_net-2.2.0\x86_64-w64-mingw32\include\SDL2 ``` 全部完成後,一樣在上方選單,選到General。將第一個方框(Add following command lines when calling the compiler)打勾,並輸入指令:(建議直接複製) ``` -lmingw32 -L/mingw64/bin -lSDL_net -lSDL_bgi -lSDL2_ttf -lSDL2_mixer -lSDL2_image -lSDL2main -lSDL2 ``` 以上三步驟,若您有部分函式庫並未用到,**請不要輸入該行**。例如: SDL2_net並未使用,則不需要輸入的部分是: ``` C:\SDL2_net-2.2.0\x86_64-w64-mingw32\lib C:\SDL2_net-2.2.0\x86_64-w64-mingw32\include\SDL2 -lSDL_net ``` ### Step 3: 測試 到 [https://lazyfoo.net/tutorials/SDL/index.php](https://lazyfoo.net/tutorials/SDL/index.php) 隨意找一篇教學下載下來,會得到該篇教學的.cpp檔和相關檔案。在您急著打開Dev-C++按下F11之前,**請記得將.dll檔案們,複製到與.cpp相同的路徑下!** 現在你可以按下F11編譯了! 檔案應該會如期執行,完成編譯。(若是有跳出執行視窗,但視窗中顯示有錯誤,那不是安裝錯誤,是程式內部邏輯的錯誤。) ### Step 4: 使用 使用時,就像是使用標準函式庫一般,直接使用: ```cpp #include <SDL.h> #include <SDL_image.h> ... ``` 完成!開啟你的絕望開發之旅吧! 若需要建立project,也不需要額外參數設定,建立完後直接使用即可。 ## Case 2: Work with Projects ### 優缺點 - 優點: 編譯其他不用SDL的程式碼時不會干涉到。 - 缺點: 每次建立新程式(有一個main出現)就需要建立一次,每次建立都要重新輸入路徑 ### Step 1: 將資源包找個地方放 不如就放在C:/吧! 最好找。請將所有資源包都放在同一個路徑底下,**不要拆開資料夾內的東西!!!**,完成後你的資料夾們應該長得像: ``` C:/ ├─ SDL2-2.24.2/ ├─ SDL2_image-2.6.2/ ⋮ ``` C:/可以換成任何你想要放的地方,暫且稱作。那麼之後遇到C:/的地方都要用路徑取代掉。 ### Step 2: 開 Project 點擊File -> New -> Project,選擇Empty Project。 輸入Project Name後按下OK即完成建立,選擇一個放project的地方,**建議放在某資料夾內**。 ### Step 3: 設定Project 按下Ctrl+H開啟設定視窗。 我們有三個部分要設定,首先是函式庫路徑,選單選到Directories -> Library Directories **逐行**輸入以下路徑到視窗底部的輸入框,完成後**按Add**: ``` C:\SDL2-2.24.2\x86_64-w64-mingw32\lib C:\SDL_bgi-2.6.0\bin\Mingw64 C:\SDL2_image-2.6.2\x86_64-w64-mingw32\lib C:\SDL2_mixer-2.6.2\x86_64-w64-mingw32\lib C:\SDL2_ttf-2.20.1\x86_64-w64-mingw32\lib C:\SDL2_net-2.2.0\x86_64-w64-mingw32\lib ``` 全部完成後,一樣在上方選單,選到Directories -> Include Directories **逐行**輸入以下路徑到視窗底部的輸入框,完成後**按Add**: ``` C:\SDL2-2.24.2\x86_64-w64-mingw32\include\SDL2 C:\SDL_bgi-2.6.0\src C:\SDL2_mixer-2.6.2\x86_64-w64-mingw32\include C:\SDL2_image-2.6.2\x86_64-w64-mingw32\include C:\SDL2_ttf-2.20.1\x86_64-w64-mingw32\include C:\SDL2_net-2.2.0\x86_64-w64-mingw32\include\SDL2 ``` 全部完成後,一樣在上方選單,選到Parameters。在最右邊的輸入框(Linkers)輸入指令:(建議直接複製) ``` -lmingw32 -L/mingw64/bin -lSDL_net -lSDL_bgi -lSDL2_ttf -lSDL2_mixer -lSDL2_image -lSDL2main -lSDL2 ``` 以上三步驟,若您有部分函式庫並未用到,**請不要輸入該行**。例如: SDL2_net並未使用,則不需要輸入的部分是: ``` C:\SDL2_net-2.2.0\x86_64-w64-mingw32\lib C:\SDL2_net-2.2.0\x86_64-w64-mingw32\include\SDL2 -lSDL_net ``` ### Step 3: 測試 到 [https://lazyfoo.net/tutorials/SDL/index.php](https://lazyfoo.net/tutorials/SDL/index.php) 隨意找一篇教學下載下來並解壓,會得到該篇教學的.cpp檔和相關檔案。現在請在Dev-C++最左欄,找到project的名字,右鍵點擊打開->點擊Add to Project,然後找到剛剛下載的.cpp檔並import到project內。 在您急著按下F11之前,**請記得將.dll檔案們,複製到與.cpp相同的路徑下!** 現在你可以按下F11編譯了!檔案應該會如期執行,完成編譯。(若是有跳出執行視窗,但視窗中顯示有錯誤,那不是安裝錯誤,是程式內部邏輯的錯誤。) ### Step 4: 使用 使用時,請使用雙引號取代尖括號: ```cpp #include "SDL.h" #include "SDL_image.h" ... ``` 完成! 開啟你的絕望開發之旅吧! ## 疑難排解 1. **Q: 安裝好了,但還是不能編譯LazyFoo的範例程式。** A: 請確定include的部分,寫入Directories -> Include Directories的路徑和include的路徑,合起來必須是該標頭檔(.h / header file)實際的位置。 例如SDL.h所在位置是C:\SDL2-2.24.2\x86_64-w64-mingw32\include\SDL2\SDL.h,若Include Directories中的路徑是C:\SDL2-2.24.2\x86_64-w64-mingw32\include\,則應該寫為 ```cpp #include <SDL2/SDL.h> ``` ## 其他版本的替代方案 ### 使用Windows電腦,但不是使用Dev-C++ 1. 自己找一下類似的設定,然後輸入該輸入的部分,大致上不會差太多。 2. 下載Dev-C++就好啦。 ### 使用Linux或MacOS 1. 買一台Windows電腦 2. 裝Windows 3. 用VirtualBox模擬Windows 4. 等其他使用者摸索完寫一篇文章給你。 對啦,我懶得研究其他系統。我也是來混3學分的好嗎。

    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