Cool! I'm happy to hearing that! Doing setups is tedious and sometimes we get weird errors. I'm glad this helped you. I'm adding some other tutorials about the basics of SDL2 and over time I'll evolve to tutorials on how to create some small games and eventually more complex games :) If you have some time, check those out as well. Happy coding!
FOR EVERYONE RUNNING INTO ERROR: "ld: library not found for -lsdl2" I was able to fix it by including the full path to each /lib/ directory in the LIBRARY_PATHS as such: LIBRARY_PATHS = -L/opt/homebrew/Cellar/sdl2/2.0.22/lib/ -L/opt/homebrew/Cellar/sdl2_image/2.0.5/lib All together this gave me the following command line prompt: g++ -std=c++11 -Wall -O0 -g -lsdl2 -lsdl2_image -Iinclude -L/opt/homebrew/Cellar/sdl2/2.0.22/lib/ -L/opt/homebrew/Cellar/sdl2_image/2.0.5/lib src/main.cpp -o build/debug/play Hope this solves it for you guys as well! :)
@@ucanhbui4039 I used different -L -I than in the video and it works for me : INCLUDE_PATH = -I include/SDL2 -I include/SDL2_image LIBRARY_PATH = -L lib/SDL2 -L lib/SDL2_image LINKER_FLAGS = -lSDL2 -lSDL2_image The reason why is that -lSDL2 does not give me the symbols i need so i add the -L for sdl2_image AND I precise every include path beacause in the original source code in SDL2_image.h, the include is not SDL2/SDL.h but SDL.h Here are my tree for the symbolic links : ├── include │ ├── SDL2 -> /opt/homebrew/Cellar/sdl2/2.0.22/include/SDL2 │ └── SDL2_image -> /opt/homebrew/Cellar/sdl2_image/2.0.5/include/SDL2 ├── lib │ ├── SDL2 -> /opt/homebrew/Cellar/sdl2/2.0.22/lib │ ├── SDL2_image -> /opt/homebrew/Cellar/sdl2_image/2.0.5/lib Much thanks to this guy video it's super clean and clear did not found something as this as good on the net, KEEP GOING WELL PLAYED
THANK YOU! This was the first tutorial that actually got SDL working on my Mac. Did not know you could install SDL with Homebrew, and I definitely did not think of doing symlinks to link to the SDL libraries. Great job!
I feel an SDL2 walkthrough from here would boost your channel so much! I had tried to follow another walkthrough and stumbled at the first issue of not being able to run CodeBlocks. Then tried another which was Eclipse based on linux and couldn't get the linker to work. Then last before finding this, I tried a vs code solution for windows, which didn't work. This finally popped up in my suggested and was the first time I saw a MacOS solution for SDL and it works! Thank you so much, please consider making more content for your channel. Your guidance is just the right level of information - not too much, not too little, and its robust!
Hey Toffy, thanks a lot for leaving this feedback. I have been super busy at my full time job and didn’t have much time to create new videos, although I still want to explorer more SDL and create some small games with it. I’m happy that this tutorial was useful to you. I hope you come back later to watch new videos when I post them. Cheers!
Great video, super clear and easy to follow! Wish I watched this before struggling for hours to get VS Code working with SDL on my Mac. Only thing I would suggest is boosting your audio volume, it's pretty quiet even with my volume all the way up.
Brilliant approach, this video not only got me to the goal; it also clearly shows best practice linking libraries every time you want to include it in your project. I did not know the ability of the 'tree' command to show the actual links, this video really made my day. My only comment is readability; My eyesight is not bad, though, I need to use accessibility options to read the command-line, and TH-cam captions are overlapping sometimes the command-line.
@@quantondev Yes, indeed. It's really nice to work with SDL2 even though it's an old API. I didn't have time yet, but I'm planning to share new tutorials on how to work with SDL2 APIs for things like reading files, loading and playing sounds, rendering elements on the screen based on tilemaps, etc. Also, I'm planning to create a series where we will be able to recreate Pacman using SDL2. That will be also fun :) Have fun, and if you create something that you want to share, feel free to upload it to youtube and share it here in the comments. Stay creative, and have fun.
@@independentpixels haha thanks. I am working on dialog bubbles to start with. I would like to share it after it finishes. It is not that easy to create an entity object to relate each other for now. I am trying to find a good way to deal with it. Looking for other projects as well. I will be back in couple of days :)
This is quite out of date. Brew puts stuff in a different location and also the Mac version of SDL framework doesnt contain static links, so the lib stuff and linker is not going to work
For those who still receive the following error : "ld: library not found for -lsdl2" Installing using "brew install sdl2" has a new default path as of 2024 which is /opt/homebrew/Cellar Instead of creating a symlink (ln -s command) between the path (/opt/homebrew/Cellar) and your project directory, simply copy the files to your directory. This can be done with the following command: cp -r /opt/homebrew/Cellar/sdl2/2.30.0/include/SDL2 [your project path] cp -r /opt/homebrew/Cellar/sdl2/2.30.0/lib [your project path] For sdl2_image I didn't encounter any errors when creating a symlink(ln -s command). If you receive a similar error for sdl2_image, follow the same steps above. Otherwise follow the video above. Hope this helps :)
So I copied all the files into their directories, yet the same error still appears (ld: library 'sdl2' not found). Any idea what I'm doing wrong? My Tree: . ├── Makefile ├── build │ └── debug ├── include │ ├── SDL2 (copied directly from Cellar) │ └── SDL2_image (copied directly from Cellar) ├── lib │ └── lib (SDL2_image library copied directly from Cellar) └── src └── main.cpp I renamed "SDL2_image" in the include folder from its previous name "SDL2", as two folders with the same name cannot exist together. I don't think this would impact anything, as the header inside does not reference the folder's name. Edit: I somehow did it. The video showed that the lib folder needed to be taken from SLD2_image. Instead, I replaced it with the lib folder from SLD2, and it worked.
Sir Thank you for your video. I have one major problem. When I am pressing debug as you did at 19:23 the terminal gives me the following error: Starting build... make spawn /bin/sh ENOENTBuild finished with error(s). * The terminal process failed to launch (exit code: -1). * Terminal will be reused by tasks, press any key to close it. Please how do I fix this Thank you
I fixed my own problem. For anyone else having this problem, just double check your launch.json and tasks.json files if they are written exactly as the video described! I had a slight bracket error.
19:10 *edit: i've noticed it's happening with "#include " pls help im getting an error it say: g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play ld: warning: dylib (/usr/local/lib/libsdl2.dylib) was built for newer macOS version (11.0) than being linked (10.15.6) Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable (maybe you meant: SDL_main()) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [all] Error 1
Hi, it seems that you don't have a main() method defined in your main.cpp file. Make sure your main.cpp file has a main() method like this: github.com/jcfausto/sdl2-starter/blob/36f49bdd8b46ae4e3d49a6ef16dd75b94037f81a/src/main.cpp#L4 You can copy the entire content of the main.cpp file from the link above just to be sure everything is alright. I believe that this should fix the problem :) From there, you can then start adding more code to your program/game. Happy coding!
The fastest fix for the "ld: library not found for -lsdl2" error would be to just chanbge -Llib to "-Llib/SDL2" - this is assuming you made a sym-link to your project/lib and there is a folder names SDL2 in there. You could also just copy the libraries into the lib folder directly and it would work as is.
Thanks man I love you for making this video, but as a beginner I don’t really understand the whole concept around (Makefile and json files) can you please make some videos like this for those topics as well
Hey thanks for investing your time to watch the video :) Sure, I like your suggestion. I can definitely do some videos explaining what those files are, etc. Thanks for your suggestion.
Thank so much you are the best I like your videos I have question, when I make a new project I should to do like first time or there is a kinda template, thank for your help.
It's great video. But can I ask a question? if I ignore LINKER_FLAGS in Makefile, my program can run? (I test it but when I import LINKER_FLAGS, vscode says: no such file or directory: lsdl2)
Using Apple's silicon puts installs the library to /opt/homebrew/* I got this error after following everything : ld: library not found for -lsdl2 will update if I got any progress
Unfortunately I don't have a M1 to ensure the project will work on both processors. I'm starting to think that maybe having the libraries added to the project directly would be a better option that would fit for all cases. 🤔
That's wonderful! I was trying to get into sdl2 but it looks like Raylib is more beginner friendly for new c++ learners. Could you make another for the Raylib(c++) on macOS + vscode ?
Thanks :) Yes, SDL2 is not super beginner friendly. The Raylib seems to be a great alternative indeed. I'll try to create another version of this setup using Raylib instead of SDL2.
when I use 'make' command in terminal of vscode, it gives the following error: g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play ld: library not found for -lsdl2 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [all] Error 1 It doesn't make any 'play' file inside 'debug' as well. I have made alias of both 'include' and 'lib' file properly.
Hey akshat, Could you please share what's the output of `brew info sdl2`? It will tell us where you have SDL2 installed on your machine. The path indicated, should match the one in the links. Could you also share please the output of (from the project directory): $ la lib/ $ la include/ With this info I might be able to help you :)
[resolved, FYI] On 2021 M1 imac, I had error when attempting to run the debugger (16:30): "Warning: Debuggee TargetArchitecture not detected, assuming x86_64. ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process exited with status -1 (attach failed ((os/kern) invalid argument)) The program '/Users/kevin/repos/learnOpenGL/build/debug/play' has exited with code 42 (0x0000002a)." I was able to resolve this by adding extension "CodeLLDB," then changing launch.json from ""type": "cppdbg"" to ""type": "lldb""
Hey, I'm glad you liked it :) The theme name is Cyberpunk and you can find it on this link here marketplace.visualstudio.com/items?itemName=max-SS.cyberpunk
Hey, I'm not entirely sure about how to achieve that as I'm writing the programs in C++. But, I think that first you'll have to rewrite some parts that are using c++ specific features to use C features. Then, compiling will be similar to what we are doing now, except that you'll invoke a different compiler "gcc" instead of "g++" and for the flags you can remove the "-std=c++11" flag. I think that should do. I can't provider more details as I'm not an expert in C. I hope this helped anyways. Thanks.
Hi! I've tried using glfw but the version my mac uses is openGL 2.3, and shaders are not available. Doing this procedure will work? (I'm using a M1 macbook)
Dont know if your still accepting questions but, i keep getting this error when trying to use a SDL2_image function g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp src/renderwindow.cpp -o build/debug/play Undefined symbols for architecture x86_64: "_IMG_Init", referenced from: _main in main-3bc8c0.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [all] Error 1 i really don't know what's causing this, any help would be appreciated
Hey :) Could it be that you need to add the linker flag -lsdl2_image to your makefile? The command to compile should look like this: g++ -std=c++11 -Wall -O0 -g -lsdl2 -lsdl2_image -Iinclude -Llib src/main.cpp src/renderwindow.cpp -o build/debug/play Also, you should make sure the the symbolic links are correc in the "/Lib" folder of the project. Sometimes the location where the libraries are installed on your machine may differ. Some other folks had similar issues. Have a look at some of the older comments down below, you might find your answer there. I hope that helps. Happy coding :)
Hey Johan, what's exactly the problem you're having? Could you please tell me more details about what's not working and in case an error message is presented to you, what does it says?
For some reasons why I try to use anything that includes SDL_image it says i need the compiler flag -lSDL_Image, which i set, but the i get "library not found for -lSDL_Image". I have no clue as to why this happens. Could you help me out?
Hey, sorry for the late reply. In this case, I'd double check the setup of the library in your project. First: Check in the /lib folder of the project that an SDL2_image directory exists and that you can expand its content. Second: If the first check pass, then check the /include directory, and verify the the SDL2_image folder exists and that you can expand its content, which should include the SDL2_image.h file only. If one of the checks above fail, I'd suggest you to re-do the setup of this library as explained in the video. Third: Assuming you're using the make command to build the project, make sure that in the Makefile's LINKER_FLAGS you have both the -lsdl2 -lsdl2_image libraries required. The output of the make command should be something like this: g++ -std=c++11 -Wall -O0 -g -lsdl2 -lsdl2_image -Iinclude -Llib src/main.cpp -o build/debug/play One last tip: Sometimes the installation path for the SDL2 libraries could be different in your machine. The links for the /lib folder on the sample project were created assuming that the SDL2 libraries are physically installed on your machine on the "/urs/local/Cellar" directory. If that's not the case, then you'll have to adjust the links. In order to check where the libraries are installed, you can use the command: "brew info sdl2_image" I hope that helps :) Happy coding!
Hello I am having issues with the Debugging Aspect (everything else works fine). My breakpoints are changed into gray hollow circles when I run the debugger. Looking on VSCode's website: "When a debugging session starts, breakpoints that cannot be registered with the debugger change to a gray hollow circle. The same might happen if the source is edited while a debug session without live-edit support is running." Anyone have any clue what I am doing wrong? Let's say my Makefile,tasks and launch are correct
Okay so I got it to work BUT the literal only thing I did was in the "launch.json" - my version was on the bottom so I moved it on the top like yours....
Hi Max, what I usually recommend is to google search the issue you're having. Usually an answer will pop up in the search results. I can try to help if you share what specific error you're facing.
really nice video, had a few questions i was hoping you might be able to clear up! do you typically use brew to install you libraries? how come you didn’t add a lib file for the standard sdl2 and only the sdl_image to your project? does sdl2 only need headers(?) when you added the sdl2 location to the include folder would this still be considered static linking? if you were to add more libraries to your project how would you change the makefile? (sorry if some of these seem silly, still trying to get my head around setting up c++ projects!)
also looking at the symlinking stuff you've done, how come the command was ln -s /usr/local/Cellar/sdl2/2.24.1/includeSDL2 ./include/SDL2 and not ln -s /usr/local/Cellar/sdl2/2.24.1/include/SDL2 ./include/SDL2 ?
Hey man thank you so much this tutorial was super helpful. I'm just still a little confused about the relationship between SDL and OpenGL. I'm interested in making 3D graphics, so I was wondering what additional libraries I need to do that.
Hey dev_web, I'm glad you liked it :) SDL is a library that was created to facilitates the access to operating system resources such as audio, keyboard, video, joysticks, gamepads, and graphic resources either through OpenGL or Direct3D. It simplifies a lot the code necessary to perform some action, like creating a window, which would be different if you're creating it on Windows, Linux, or Mac. In order to create 3D graphics, my current understanding is that you'll have to use OpenGL sooner or later. You can definitely you SDL and OpenGL in combination, that won't be a problem. In the SDL's official tutorials page there are some examples about how to use SDL with OpenGL: wiki.libsdl.org/Tutorials Also, I'd recommend having a look at other libraries as well like GLFW or GLEW, they're as also very good libraries and I think I'd choose one of these if I wanted to create 3D games or so. Happy learning!
@@independentpixels ok cool thank you, it makes a lot more sense now. So in theory, if I install the glew and glfw libraries and link them to my include folder on the build I should be able to use them? I’m assuming my .json files will have to be a little different as well?
@@dev_web3903 I'm not 100% sure, but I think that the same process would work. I was reading briefly the GLFW docs and it seems that once you download and unzip the library all you have to do is to link to the folder containing the headers and the libs. So, in theory, the same approach I used on this tutorial should work. If that does not work, then and alternative is to copy the folders containing the headers files directly into to your project. That's also a common practice. :)
Hi.When I try to use "make" command, I get g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play ld: library 'sdl2' not found message. Can anyone help me?
the first test build of main.cpp I get an error -> g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play ld: library not found for -lsdl2 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [all] Error 1 Any help would be greatly appreciated. Thank you!
Thank you so much! I spent over an hour trying to figure out how to set up SDL2 on mac, and then after I found your video, I did it in twenty minutes!
Cool! I'm happy to hearing that! Doing setups is tedious and sometimes we get weird errors. I'm glad this helped you.
I'm adding some other tutorials about the basics of SDL2 and over time I'll evolve to tutorials on how to create some small games and eventually more complex games :) If you have some time, check those out as well.
Happy coding!
FOR EVERYONE RUNNING INTO ERROR: "ld: library not found for -lsdl2"
I was able to fix it by including the full path to each /lib/ directory in the LIBRARY_PATHS as such:
LIBRARY_PATHS = -L/opt/homebrew/Cellar/sdl2/2.0.22/lib/ -L/opt/homebrew/Cellar/sdl2_image/2.0.5/lib
All together this gave me the following command line prompt:
g++ -std=c++11 -Wall -O0 -g -lsdl2 -lsdl2_image -Iinclude -L/opt/homebrew/Cellar/sdl2/2.0.22/lib/ -L/opt/homebrew/Cellar/sdl2_image/2.0.5/lib src/main.cpp -o build/debug/play
Hope this solves it for you guys as well! :)
i try your way but i still have a problem when include sdl2_image and sdl2_ttf . It is"sdl2_image not found". Could you help me with that please?
@@ucanhbui4039 I used different -L -I than in the video and it works for me :
INCLUDE_PATH = -I include/SDL2 -I include/SDL2_image
LIBRARY_PATH = -L lib/SDL2 -L lib/SDL2_image
LINKER_FLAGS = -lSDL2 -lSDL2_image
The reason why is that -lSDL2 does not give me the symbols i need so i add the -L for sdl2_image AND I precise every include path beacause in the original source code in SDL2_image.h, the include is not SDL2/SDL.h but SDL.h
Here are my tree for the symbolic links :
├── include
│ ├── SDL2 -> /opt/homebrew/Cellar/sdl2/2.0.22/include/SDL2
│ └── SDL2_image -> /opt/homebrew/Cellar/sdl2_image/2.0.5/include/SDL2
├── lib
│ ├── SDL2 -> /opt/homebrew/Cellar/sdl2/2.0.22/lib
│ ├── SDL2_image -> /opt/homebrew/Cellar/sdl2_image/2.0.5/lib
Much thanks to this guy video it's super clean and clear did not found something as this as good on the net,
KEEP GOING WELL PLAYED
@@Proplaysmobilegame I had exactly the same thing as yours, it still gives cannot find "ld: library not found for -lSDL2", darn it
@@Proplaysmobilegame thank you so much! this pretty much fixed all the issues i had. i also had to change the include code to look like "#include ".
Except on the latest brew install and mac download, there is no "lib" folder in the SDL Framework
THANK YOU! This was the first tutorial that actually got SDL working on my Mac. Did not know you could install SDL with Homebrew, and I definitely did not think of doing symlinks to link to the SDL libraries. Great job!
could you please tell me what version of mac os you have, because for some reason this solution does not apply to mac os 14
Thank you so much, your tutorial is very clear and concise and with comfortable speed. And you have such an amazing voice!
I feel an SDL2 walkthrough from here would boost your channel so much!
I had tried to follow another walkthrough and stumbled at the first issue of not being able to run CodeBlocks. Then tried another which was Eclipse based on linux and couldn't get the linker to work. Then last before finding this, I tried a vs code solution for windows, which didn't work.
This finally popped up in my suggested and was the first time I saw a MacOS solution for SDL and it works! Thank you so much, please consider making more content for your channel. Your guidance is just the right level of information - not too much, not too little, and its robust!
Hey Toffy, thanks a lot for leaving this feedback. I have been super busy at my full time job and didn’t have much time to create new videos, although I still want to explorer more SDL and create some small games with it. I’m happy that this tutorial was useful to you. I hope you come back later to watch new videos when I post them. Cheers!
Great video, super clear and easy to follow! Wish I watched this before struggling for hours to get VS Code working with SDL on my Mac. Only thing I would suggest is boosting your audio volume, it's pretty quiet even with my volume all the way up.
Thanks for the feedback 👍 Yeah, the audio is not the best. I’ll improve it for the next videos 🙌
Wow, thanks so much! Amazingly clear and helpful tutorial! Please make some more SDL2 tutorials, you are great!
Thanks for this feedback :) I really appreciate it. Happy coding!
Brilliant approach, this video not only got me to the goal; it also clearly shows best practice linking libraries every time you want to include it in your project. I did not know the ability of the 'tree' command to show the actual links, this video really made my day. My only comment is readability; My eyesight is not bad, though, I need to use accessibility options to read the command-line, and TH-cam captions are overlapping sometimes the command-line.
Thank you so much. This is the only tutorial that gets sdl2 to work on mac properly. Now I can fly trough
You're welcome!
@@independentpixels actually. I find sdl so good. I will keep going with this. This is so fun
@@quantondev Yes, indeed. It's really nice to work with SDL2 even though it's an old API. I didn't have time yet, but I'm planning to share new tutorials on how to work with SDL2 APIs for things like reading files, loading and playing sounds, rendering elements on the screen based on tilemaps, etc. Also, I'm planning to create a series where we will be able to recreate Pacman using SDL2. That will be also fun :)
Have fun, and if you create something that you want to share, feel free to upload it to youtube and share it here in the comments.
Stay creative, and have fun.
@@independentpixels haha thanks.
I am working on dialog bubbles to start with. I would like to share it after it finishes. It is not that easy to create an entity object to relate each other for now. I am trying to find a good way to deal with it. Looking for other projects as well. I will be back in couple of days :)
This is quite out of date. Brew puts stuff in a different location and also the Mac version of SDL framework doesnt contain static links, so the lib stuff and linker is not going to work
Wow dude, you are explaining very well! immediately subscribed
Awesome tutorial - everything was explained really well. Thank you!
Exactly what I was looking for. Thanks!
Could you update this for Ventura and current SDL2? So much has changed.
ld: library not found for -lsdl2
At 4:53, there is no `sdl2_image1 directory present for me, even though I followed your instructions to this point. Anyone else experienced that?
For those who still receive the following error : "ld: library not found for -lsdl2"
Installing using "brew install sdl2" has a new default path as of 2024 which is /opt/homebrew/Cellar
Instead of creating a symlink (ln -s command) between the path (/opt/homebrew/Cellar) and your project directory, simply copy the files to your directory.
This can be done with the following command:
cp -r /opt/homebrew/Cellar/sdl2/2.30.0/include/SDL2 [your project path]
cp -r /opt/homebrew/Cellar/sdl2/2.30.0/lib [your project path]
For sdl2_image I didn't encounter any errors when creating a symlink(ln -s command). If you receive a similar error for sdl2_image, follow the same steps above.
Otherwise follow the video above.
Hope this helps :)
So I copied all the files into their directories, yet the same error still appears (ld: library 'sdl2' not found). Any idea what I'm doing wrong?
My Tree:
.
├── Makefile
├── build
│ └── debug
├── include
│ ├── SDL2 (copied directly from Cellar)
│ └── SDL2_image (copied directly from Cellar)
├── lib
│ └── lib (SDL2_image library copied directly from Cellar)
└── src
└── main.cpp
I renamed "SDL2_image" in the include folder from its previous name "SDL2", as two folders with the same name cannot exist together. I don't think this would impact anything, as the header inside does not reference the folder's name.
Edit: I somehow did it. The video showed that the lib folder needed to be taken from SLD2_image. Instead, I replaced it with the lib folder from SLD2, and it worked.
Sir Thank you for your video.
I have one major problem. When I am pressing debug as you did at 19:23 the terminal gives me the following error:
Starting build...
make
spawn /bin/sh ENOENTBuild finished with error(s).
* The terminal process failed to launch (exit code: -1).
* Terminal will be reused by tasks, press any key to close it.
Please how do I fix this Thank you
I fixed my own problem. For anyone else having this problem, just double check your launch.json and tasks.json files if they are written exactly as the video described! I had a slight bracket error.
Hi, thank you for your video, it helps me a lot, and I'm curious what theme you use in this video for your VSCode :D it looks good
19:10 *edit: i've noticed it's happening with "#include " pls help im getting an error it say:
g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play
ld: warning: dylib (/usr/local/lib/libsdl2.dylib) was built for newer macOS version (11.0) than being linked (10.15.6)
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: SDL_main())
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
Hi, it seems that you don't have a main() method defined in your main.cpp file. Make sure your main.cpp file has a main() method like this: github.com/jcfausto/sdl2-starter/blob/36f49bdd8b46ae4e3d49a6ef16dd75b94037f81a/src/main.cpp#L4
You can copy the entire content of the main.cpp file from the link above just to be sure everything is alright.
I believe that this should fix the problem :)
From there, you can then start adding more code to your program/game.
Happy coding!
This is what i get when i run the terminal "make"
make: *** No targets. Stop.
Can you take a look and help me fix it? Thank you so much
Command `make` only works when there is a Makefile in the particular path you're in. Check if you really have a `Makefile`.
The fastest fix for the "ld: library not found for -lsdl2" error would be to just chanbge -Llib to "-Llib/SDL2" - this is assuming you made a sym-link to your project/lib and there is a folder names SDL2 in there. You could also just copy the libraries into the lib folder directly and it would work as is.
hi! could you please help with solving this problem? i would be very thankful and happy if you could)
I don't have a g++ build and debug active file: 13:14 . Why is that happening?
I do get a launch.json file, but not with all the tags that are in your video
Thank you so much. very helpful !
Thanks man I love you for making this video, but as a beginner I don’t really understand the whole concept around (Makefile and json files) can you please make some videos like this for those topics as well
Hey thanks for investing your time to watch the video :) Sure, I like your suggestion. I can definitely do some videos explaining what those files are, etc. Thanks for your suggestion.
@@independentpixels +1
Thank you ver much,it is wonderful video.hope the next video.
Hi can you please make a video on how we can install SDL BGI on mac
Thank so much you are the best I like your videos I have question, when I make a new project I should to do like first time or there is a kinda template, thank for your help.
can’t compile x86_64 version of libSDL under MacOS X using brew
It's great video. But can I ask a question? if I ignore LINKER_FLAGS in Makefile, my program can run? (I test it but when I import LINKER_FLAGS, vscode says: no such file or directory: lsdl2)
Awesome, thank you very much!
Using Apple's silicon puts installs the library to /opt/homebrew/*
I got this error after following everything :
ld: library not found for -lsdl2
will update if I got any progress
Unfortunately I don't have a M1 to ensure the project will work on both processors. I'm starting to think that maybe having the libraries added to the project directly would be a better option that would fit for all cases. 🤔
That's wonderful! I was trying to get into sdl2 but it looks like Raylib is more beginner friendly for new c++ learners. Could you make another for the Raylib(c++) on macOS + vscode ?
Thanks :) Yes, SDL2 is not super beginner friendly. The Raylib seems to be a great alternative indeed. I'll try to create another version of this setup using Raylib instead of SDL2.
@@independentpixels Great news! I'll be waiting, thanks again.
when I use 'make' command in terminal of vscode, it gives the following error:
g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play
ld: library not found for -lsdl2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
It doesn't make any 'play' file inside 'debug' as well.
I have made alias of both 'include' and 'lib' file properly.
Hey akshat,
Could you please share what's the output of `brew info sdl2`?
It will tell us where you have SDL2 installed on your machine. The path indicated, should match the one in the links.
Could you also share please the output of (from the project directory):
$ la lib/
$ la include/
With this info I might be able to help you :)
cannot open source file "SDL2/SDL_image.h" or cannot open source file "SDL2_image/SDL_image.h"
Thank you so much!
good video but the console font is really small
[resolved, FYI] On 2021 M1 imac, I had error when attempting to run the debugger (16:30):
"Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process exited with status -1 (attach failed ((os/kern) invalid argument))
The program '/Users/kevin/repos/learnOpenGL/build/debug/play' has exited with code 42 (0x0000002a)."
I was able to resolve this by adding extension "CodeLLDB," then changing launch.json from ""type": "cppdbg"" to ""type": "lldb""
Hey Everything Engineer, I'm glad you fixed it. Thanks for sharing the solution here. It might be helpful to other colleagues as well. 👍
Could you include SDL2 on mac m1? I had an error: "cannot open source file "SDL2/SDL.h"
I guess I already had sdl2 installed?
thanks for the tutorial :) where can I find that vscode theme
Hey, I'm glad you liked it :) The theme name is Cyberpunk and you can find it on this link here marketplace.visualstudio.com/items?itemName=max-SS.cyberpunk
thank you
Hey for your COMPILER_FLAGS how do I switch out C++ for just C?
Hey, I'm not entirely sure about how to achieve that as I'm writing the programs in C++. But, I think that first you'll have to rewrite some parts that are using c++ specific features to use C features. Then, compiling will be similar to what we are doing now, except that you'll invoke a different compiler "gcc" instead of "g++" and for the flags you can remove the "-std=c++11" flag.
I think that should do. I can't provider more details as I'm not an expert in C. I hope this helped anyways. Thanks.
Hi! I've tried using glfw but the version my mac uses is openGL 2.3, and shaders are not available.
Doing this procedure will work? (I'm using a M1 macbook)
Dont know if your still accepting questions but, i keep getting this error when trying to use a SDL2_image function
g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp src/renderwindow.cpp -o build/debug/play
Undefined symbols for architecture x86_64:
"_IMG_Init", referenced from:
_main in main-3bc8c0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
i really don't know what's causing this, any help would be appreciated
Hey :)
Could it be that you need to add the linker flag -lsdl2_image to your makefile?
The command to compile should look like this:
g++ -std=c++11 -Wall -O0 -g -lsdl2 -lsdl2_image -Iinclude -Llib src/main.cpp src/renderwindow.cpp -o build/debug/play
Also, you should make sure the the symbolic links are correc in the "/Lib" folder of the project. Sometimes the location where the libraries are installed on your machine may differ.
Some other folks had similar issues. Have a look at some of the older comments down below, you might find your answer there.
I hope that helps.
Happy coding :)
dude , you are a life saver
Glad I could help!
hi , i get this error, "clang: error: unknown argument: '-00'
make: *** [all] Error 1" while running "make" from terminal
any ideas how to solve that/
The flag is '-O0'
I am having a problem when i want to include sdl2/sdl_image. Can you please help?
Hey Johan, what's exactly the problem you're having? Could you please tell me more details about what's not working and in case an error message is presented to you, what does it says?
For some reasons why I try to use anything that includes SDL_image it says i need the compiler flag -lSDL_Image, which i set, but the i get "library not found for -lSDL_Image". I have no clue as to why this happens. Could you help me out?
Hey, sorry for the late reply.
In this case, I'd double check the setup of the library in your project.
First: Check in the /lib folder of the project that an SDL2_image directory exists and that you can expand its content.
Second: If the first check pass, then check the /include directory, and verify the the SDL2_image folder exists and that you can expand its content, which should include the SDL2_image.h file only.
If one of the checks above fail, I'd suggest you to re-do the setup of this library as explained in the video.
Third: Assuming you're using the make command to build the project, make sure that in the Makefile's LINKER_FLAGS you have both the -lsdl2 -lsdl2_image libraries required.
The output of the make command should be something like this:
g++ -std=c++11 -Wall -O0 -g -lsdl2 -lsdl2_image -Iinclude -Llib src/main.cpp -o build/debug/play
One last tip: Sometimes the installation path for the SDL2 libraries could be different in your machine. The links for the /lib folder on the sample project were created assuming that the SDL2 libraries are physically installed on your machine on the "/urs/local/Cellar" directory. If that's not the case, then you'll have to adjust the links. In order to check where the libraries are installed, you can use the command: "brew info sdl2_image"
I hope that helps :) Happy coding!
Hi Julio,
Could you please help with below error....?
g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src -o build/debug/play
ld: can't map file, errno=22 file 'src' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
I found the issue in Makefile, after we complete the line, there should be no spaces before we move to the next line.
Nice! I'm happy that you found the solution for the issue :) Happy coding!
wherever you are, thank you for this post. was losing my mind over this error and it ended up being a trailing space like you said. 🙏
Unfortunately, I can't read the commands. Real pity. =(
Hello I am having issues with the Debugging Aspect (everything else works fine).
My breakpoints are changed into gray hollow circles when I run the debugger. Looking on VSCode's website:
"When a debugging session starts, breakpoints that cannot be registered with the debugger change to a gray hollow circle. The same might happen if the source is edited while a debug session without live-edit support is running."
Anyone have any clue what I am doing wrong? Let's say my Makefile,tasks and launch are correct
Okay so I got it to work BUT the literal only thing I did was in the "launch.json" - my version was on the bottom so I moved it on the top like yours....
@@ohlorduser Awesome! Great to hear that you fixed the issue 👍Happy coding!
I don't reach to install sdl2 with brew
Hi Max, what I usually recommend is to google search the issue you're having. Usually an answer will pop up in the search results. I can try to help if you share what specific error you're facing.
@@independentpixels I got many errors when I used the command ?
Do you have a email or something to chat ?
That's will be better
really nice video, had a few questions i was hoping you might be able to clear up!
do you typically use brew to install you libraries?
how come you didn’t add a lib file for the standard sdl2 and only the sdl_image to your project? does sdl2 only need headers(?)
when you added the sdl2 location to the include folder would this still be considered static linking?
if you were to add more libraries to your project how would you change the makefile?
(sorry if some of these seem silly, still trying to get my head around setting up c++ projects!)
also looking at the symlinking stuff you've done, how come the command was
ln -s /usr/local/Cellar/sdl2/2.24.1/includeSDL2 ./include/SDL2
and not
ln -s /usr/local/Cellar/sdl2/2.24.1/include/SDL2 ./include/SDL2
?
Hey man thank you so much this tutorial was super helpful. I'm just still a little confused about the relationship between SDL and OpenGL. I'm interested in making 3D graphics, so I was wondering what additional libraries I need to do that.
Hey dev_web, I'm glad you liked it :)
SDL is a library that was created to facilitates the access to operating system resources such as audio, keyboard, video, joysticks, gamepads, and graphic resources either through OpenGL or Direct3D. It simplifies a lot the code necessary to perform some action, like creating a window, which would be different if you're creating it on Windows, Linux, or Mac.
In order to create 3D graphics, my current understanding is that you'll have to use OpenGL sooner or later. You can definitely you SDL and OpenGL in combination, that won't be a problem.
In the SDL's official tutorials page there are some examples about how to use SDL with OpenGL: wiki.libsdl.org/Tutorials
Also, I'd recommend having a look at other libraries as well like GLFW or GLEW, they're as also very good libraries and I think I'd choose one of these if I wanted to create 3D games or so.
Happy learning!
@@independentpixels ok cool thank you, it makes a lot more sense now. So in theory, if I install the glew and glfw libraries and link them to my include folder on the build I should be able to use them? I’m assuming my .json files will have to be a little different as well?
@@dev_web3903 I'm not 100% sure, but I think that the same process would work. I was reading briefly the GLFW docs and it seems that once you download and unzip the library all you have to do is to link to the folder containing the headers and the libs. So, in theory, the same approach I used on this tutorial should work.
If that does not work, then and alternative is to copy the folders containing the headers files directly into to your project. That's also a common practice. :)
@@independentpixels Ok awesome I'll give it a try, thank you for your help it is much appreciated.
Hi.When I try to use "make" command, I get
g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play
ld: library 'sdl2' not found
message. Can anyone help me?
the first test build of main.cpp I get an error -> g++ -std=c++11 -Wall -O0 -g -lsdl2 -Iinclude -Llib src/main.cpp -o build/debug/play
ld: library not found for -lsdl2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1 Any help would be greatly appreciated. Thank you!
same problem, did you figure it out?
same here, have you guys figured it out? i would be very happy and thankful @@jonahreisner8044
i have a problem when include sdl2_image. It is"sdl2_image not found". Could you help me with that please?