Author Topic: Help getting SDL2 to work in Code Blocks  (Read 16925 times)

Offline MrBeverage

  • Single posting newcomer
  • *
  • Posts: 1
Help getting SDL2 to work in Code Blocks
« on: April 09, 2025, 05:07:49 pm »
I'm new to programming, and very frustrated with IDEs.
I'm running MX Linux (Debian based).
I can compile successfully with: $ gcc -o main main.c `pkg-config --cflags --libs sdl2, SDL2_image`
But how do I configure CodeBlocks use the same command??? (or at least achieve the same result).
I would appreciate some DETAILED help.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7806
    • My Best Post
Re: Help getting SDL2 to work in Code Blocks
« Reply #1 on: April 15, 2025, 05:58:53 pm »
1. Setup Code::Blocks toolchain
2. Create empty project
3. Add "`pkg-config --cflags`"  to "other compiler options" include the slant quotes do not include the double quotes
4. Add " `pkg-config --libs sdl2, SDL2_image`" to "other linker option" include the slant quotes do not include the double quotes

Remember edit the project options under Project -> Build options

Link to CB Wiki https://wiki.codeblocks.org/index.php/Main_Page

Tim S.
« Last Edit: August 06, 2025, 07:21:34 pm by stahta01 »
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Krice

  • Almost regular
  • **
  • Posts: 174
Re: Help getting SDL2 to work in Code Blocks
« Reply #2 on: April 17, 2025, 09:45:38 am »
Or you can add libraries to Build options - Linker settings:

libSDL2main
libSDL2

Maybe SDL2_Image can be added also there, but at least with plain SDL2 it works like that. On Linux you don't even need to add libraries location, but on Windows you might need to do that for Code::Blocks to find where SDL2 is installed.

Offline caneskyd

  • Single posting newcomer
  • *
  • Posts: 1
    • Space Waves
Re: Help getting SDL2 to work in Code Blocks
« Reply #3 on: Yesterday at 06:19:07 am »
1. Setup Code::Blocks toolchain
2. Create empty project
3. Add "`pkg-config --cflags`"  to "other compiler options" include the slant quotes do not include the double quotes
4. Add " `pkg-config --libs sdl2, SDL2_image`" to "other linker option" include the slant quotes do not include the double quotes

Remember edit the project options under Project -> Build options

Link to CB Wiki https://wiki.codeblocks.org/index.php/Main_Page

Tim S.
it's not work

Offline Deanuglas

  • Single posting newcomer
  • *
  • Posts: 1
Re: Help getting SDL2 to work in Code Blocks
« Reply #4 on: Yesterday at 09:18:30 am »
In Code::Blocks you just need to mirror the gcc command: add pkg-config --cflags sdl2 SDL2_image in the compiler options, and pkg-config --libs sdl2 SDL2_image in the linker options. That way the IDE builds the same way as your terminal command.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1771
Re: Help getting SDL2 to work in Code Blocks
« Reply #5 on: Yesterday at 09:34:34 am »
Profile spammer caneskyd reported to moderator.