Cannot find -lSDLmain and -lSDL when compiling simple SDL program with g++ - c++

I installed SDL2 for mingw using this guide. However, when i try to compile using the compilation syntax and test code they provide, only with my own file names, I get the error shown here. I assume that this error has something to do with a problem in the way I installed SDL, as the installation instructions did not exactly match the files with which I was provided, but I did my best to follow them. Could they problem be something else? If not what is the correct way to install SDL2 for mingw?
Note: I do have the SDL2.dll file in the sdltest folder where I try to compile the program.

One way to let MinGW know where your SDL libraries are would be to create environment variable named "LIBRARY_PATH" with the value as the path to the directory containing the libraries. Similarly, you can have "CPLUS_INCLUDE_PATH" for the headers as well.
Did you follow step 2 of that tutorial ?

Related

SFML headers not found when compiling using CMake and GCC (MacOS Sierra)

I have been trying to use SFML in a CMake project, specifically the header SFML/Audio.hpp. I installed SMFL using Homebrew, and both the .dylib-files and the headers should be located correctly, in /usr/local/lib and /usr/local/include, respectively.
Now running CMake works fine, telling me that it has Found SFML 2.4.2 in /usr/local/include.
However, when compiling the project (using make), I get the following error:
/path/to/project.hpp:12:10: fatal error: 'SFML/Audio.hpp' file not found.
Does anyone know why this is happening?
Note: Compiling works fine for colleagues of mine using the same CMake- and source files on various Linux operating systems.
This sounds like you simply forgot to add SFML's include directory. On Linux, they probably install SFML to some system path where GCC (or Clang) look by default, so they don't need any additional CMake directives.
Luckily, fixing this is pretty simple.
Add the following line to your CMakeLists.txt somewhere before defining targets:
include_directories(${SFML_INCLUDE_DIR})
The variable SFML_INCLUDE_DIR is populated when you successfully call find_package(SFML...).
While you're at it, you might also want to ensure to link to the proper library files in the correct order:
target_link_libraries(myTargetName ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
Again, both variables are populated automatically.

glfw3 for code::blocks 16.01 in ubuntu

I am facing a really for me time-expensive problem. I am new to ubuntu and want to start learning more about opengl by using the glfw. Of course I cannot switch the OS so I will have to stay at ubuntu. I have come so far that I installed the glfw( by following this "tutorial": 2. step by filipwasil), so I have got an include directory in the usr/local dir, aswell as a lib directory. The include directory contains the glfw3.h and the lib directory the libglfw3.a file. If I try to add them to my project in code::blocks it seems like only the include part works, because I can see the functions provided by the glfw while typing, but once I want to compile and run the project, I get an error for each glfw function call: like "not defined reference to e.g. glfwInit". The lib directory also contains a cmake dir, which contains glfwconfig and glfwtarget files, but I really do not know what these files should do. I also noticed the question by Artur, which is quiet identical, but it does not help me because I want to know which files exactly I have to add in order to get a running window. So may question is: How is it possible to make the code::blocks IDE, actually the gcc compiler, know whats behind the glfw functions?
Every help will be appreciated. Sorry for my bad english. :)
Add GL, GLEW and glfw in the linker settings. Note the "glfw" in lowercase

MinGW "undefined reference to IMG_Load/IMG_Init/IMG_Quit" LazyFoo

I am going off of LazyFoo's SDL2 tutorials for C++ using the MinGW g++ compiler (using console). I have followed his page here, step-for-step. I have finally come across this error after having downloaded his example.
I have seen plenty of people online struggle with SDL_Image, but I've not yet seen this and I haven't found any solution to it yet.
I've loaded the include and lib folders with the proper assets
I've copied all necessary .dll's to my compile destination
The example LazyFoo provides includes for SDL_Image and SDL itself
(this question my sound redundant, but I've yet to come across a solution that applies to console-compilation)
Based on the comments above, the answer seems to be:
You need to install the development libraries for SDL_image.
You can download them here: https://www.libsdl.org/projects/SDL_image/
(look under the heading "Development libraries").
You need to ensure the path where the libSDL2_image.a file resides is in the linker search path. One way of doing this is to add an appropriate -L parameter to the link command. You could also drop the file in the default library search path.
I've had this problem in linux. the solution is simple.
add to linker:
-lSDL2_image -g `sdl2-config --cflags --libs`
I had the same problem, and the solution was to include the SDL2main library in linker parameters.
For Dev-C++ IDE you can follow the instructions below:
Get SDL or SDL2 working correctly with Dev-C++

SDL.h not found on g++ compile

Using OSX and vim...
Downloaded SDL2 from the website, then moved the SDL2.framework into /Library/Frameworks/
Using tutorial code, and Makefile... SDL.h is not found.
Makefile: g++sdl-config --cflags --libssdltest.cpp -o sdltest
I've read numerous things about pointing the compiler to the framework, but everything I've tried doesn't seem to work, and I thought /Library/Frameworks/ was the default area for the compiler to look
Got it to work.
Getting this to work took multiple tries, but the root of the issue for each try was that most of the Tutorials I was looking at were for SDL1.2 when I was using SDL2.
This changed flags in the make file, directories to search in and other things. Interestingly, I could never get the compiler to see SDL.h when it was in the /Library/Frameworks/ directory. However using Macports to install SDL2 allowed me to point the compiler to where Macports installed SDL2 header files - /opt/local/include/SDL2
That seems to have done it for me
Thank you for your question, because I was having similar difficulties! There seems to be a dearth of detailed and helpful tutorials on how to install SDL2 using Macports.
I got it working! Here are the steps:
Visit this link to find the Macports package appropriate for your version of Mac OS X. Install the version you need, and once that is done, proceed to step 2.
https://www.macports.org/install.php
After installation is done, visit this link to find the SDL2 port.
https://www.macports.org/ports.php?by=name&substr=libsdl
The one I needed was the third from the top, called libsdl2. I will be providing the name for you so feel free to visit the link simply for your own edification.
Open the Terminal, and type sudo port install libsdl2. If all goes to plan, you should see it installing and updating. Once it is complete, you should have a functional installation of the SDL2 Header files, (ending in .h), Static Library files (ending in .a) and Dynamic Library files (which contain dylib). You may have to do some poking around in Finder to locate where it installed.
The advantage of this workaround is the ability to use SDL with other IDE's besides Xcode, Eclipse for instance. Whereas Xcode requires you to assign a path of /Library/Frameworks, this technique should allow you to use the IDE of your choosing.
The final step is going into your IDE and assigning the build paths to these newly installed and compiled SDL files. For instance, the paths for mine are /opt/local/include and /opt/local/lib. Be mindful of the fact that your path may differ from these, but these examples should give you an idea of where to look.
Hopefully this is helpful for somebody!

Linking SDL_ttf library in C++

I'm having a problem linking SDL_ttf library with C++ compiler. I have tried three different programs and i couldn't solve the problem in any of them. I've tried Dev C++, Eclipse and CodeBlocks. In all of them it appeared a different error, but all related to not finding -lSDL_ttf or not recognizing the functions of that library.
I'm following this tutorial http://lazyfoo.net/SDL_tutorials/ and have done everything i have found on the internet. I copy the .h file inside /include/SDL/ directory, the .dll files inside the project directory, and the files within /lib directory into the /lib directory that i am using. I think the error might be here, as SDL_image for example, have ".lib" files, and in ttf there is no such file. They are all ".a" or ".la". I'm new to C++ so i don't know if i am doing something wrong.
Thank anyone for his help.
The error in code blocks is the following:
ld.exe cannot find -lSDL_ttf
Make sure you downloaded the correct version of the library. If you have ".a" files, you probably downloaded the mingw version. And for that you have to use a mingw compiler. If you are using something like Visual Studio, you need the version with -VC.zip at the end.
Hope it was useful.
Good coding ;-)