MinGW "undefined reference to IMG_Load/IMG_Init/IMG_Quit" LazyFoo - c++

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++

Related

Missing dll's when compiling c++ programs using mingw compiler in cygwin

When I compile my c++ programs in cygwin with the mingw compiler, the resulting executables don't run because they're missing the following dll's:
libstdc++-6.dll
libgcc_s_seh-1.dll
libwinpthread-1.dll
An example of a compilation command:
$ x86_64-w64-mingw32-g++ -Wall deque.cc -o deque
I've tried adding the following linker options as well:
-static -static-libgcc -static-libstdc++
But they don't seem to be helping either.
I went looking through my dll's at:
C:\cygwin\lib\gcc\x86_64-w64-mingw32\5.4.0
But couldn't find the dll's there. Is it possible I just don't have these dll's on my computer? If so, where would I get them?
I understand there are other similar questions on stackoverflow, but looking through them I couldn't find any solid answers to this variation of the question.
Use https://cygwin.com/packages/ to search the contents of cygwin packages.
As reported by
https://cygwin.com/cgi-bin2/package-cat.cgi?file=x86_64%2Fmingw64-x86_64-gcc-g%2B%2B%2Fmingw64-x86_64-gcc-g%2B%2B-5.4.0-3&grep=libstdc%2B%2B-6.dll
usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll
same for
usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll
usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll
I´ve had the same problem when compiling.
I decided to make a new instalation of cygwin, I followed instructions for a fresh instalation of cygwin from:
https://gist.github.com/patrickmoffitt/30684ec23fe82eabe0e3609cab2425b2
(in the point 6) using the package manager, selected the packages to install.... but in my case I also needed to install:
make
gdb
https://www.jetbrains.com/help/clion/quick-tutorial-on-configuring-clion-on-windows.html#Cygwin
At this point, when finish my new instalation, i added in the enviroment variables this route:
C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin
(this route is where the .dll are)
This worked for me, hope this could help.
Another solution is, copying all the required .dll (form the path I mentioned) and pasting them where the .exe is. Do this every time is a bit annoying.

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

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 ?

gnu compiler from the command line

Im learning c++ and I compile from the command line. I have a problem when it comes to trying to add 3rd party libraries. I cant seam to figure out the linker system. Does anyone know a good tutorial or something like that?
For example I want to play around with the SDL2 library and ill use a command like this.
c++ -I/Library/Frameworks/SDL2.framework/Headers -L/Library/Frameworks/SDL2.framework/ -lSDL2 helloworld.cpp
and I get the error ld: library not found for -lSDL2
You need to put the linking flags last on the line:
g++ -I/Library/Frameworks/SDL2.framework/Headers helloworld.cpp -L/Library/Frameworks/SDL2.framework/ -lSDL2
I found out the answer. The following command compiled correctly. The include statement had to be changed to...
#include<SDL2/SDL.h>
and the correct compile command is...
c++ -o helloworld helloWorld.cpp -framework SDL2
I could also have used g++. On my system both c++ and g++ are symlinks to the same gnu compiler which happens to be the latest version I have installed on the system.
the option -L is a unix linker option and does not work on a MAC. The dev's for GCC were kind enough to include MAC specific linker options in the form of -framework. These serve to follow the mac tradition of how and where they like to store libraries. You can link several frameworks together by separating them with a comma. So for example i could also do -framework SDL2,SDL2_mixer as long as my source has
#include<SDL2_mixer/SDL_mixer.h>
When compiling this default search location for libraries is /Library/Frameworks. The include statement is cross platform compatable and the mac gnu linker knows that if I say
#include<SDL2/SDL.h>
that that header will be found at /Library/Frameworks/SDL2.framework/Headers
The -IPATH option still works on mac and can be used to pass alternate search locations for header and source files just like it works in unix.

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 Libraries in Xcode

I'm using a powerbook (osx 10.5) and recently downloaded and installed FFTW 3.2 (link text). I've been able to compile and run some simple programs based on the online tutorial using the terminal:
g++ main.cpp -lfftw3 -lm
However, I can't get the same program to compile in Xcode. I get a linking error, "symbol(s) not found". There is a file called libfftw3.a in /usr/local/lib. How can this be linked? Furthermore, apparently the libraries have to be linked in a particular order, i.e. see: link text
thanks for any help
To link to a .a library like this in Xcode you need to:
Double-click on your target or application in Xcode to open the Info window
Switch to the "Build" tab
Add -lfftw3 to "Other Linker Flags" (under "Linking")
Add the path to your library to the "Library Search Paths" (under "Search Paths"). In your case this will be /usr/local/lib
We use FFTW (it's great by the way), this works for us!
Did you set these options for the target?
Under "Linking->Other Linker Flags" add: "-L/path/to/library -lfftw3 -lm"
warning in /Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libfftw3.a, file is not of required architecture
Maybe the binary format was different e.g. the library could be 32 bit while the application 64.
OK - I finally got this working. I also needed the the GNU Scientific Libraries and ran into similar issues with the architecture setting. For anyone interested, this tutorial goes through how to set up Xcode and link libraries:
https://web.archive.org/web/20101006023300/http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31