undefined reference to 'IMG_Load' and 'IMG_Init' [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 months ago.
I've been trying to figure out why those functions are undefined. I have been looking for hours trying to find a solution and haven't found any that worked. The closest one told me to download an earlier version of SDL_image, which worked but then told me SDL.dll was missing, insisting that I would need to use an older version of SDL.
Exact error message:
This is what my Makefile looks like:
g++ main.cpp -Isrc/include -Isrc/include/SDL2 -Iinclude/headers -Lsrc/lib -g -o main -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
This is what my lib folder looks like:
And yes, the include folder does have SDL_image.h
Additional question, I want to put all my .dll files in a bin folder but I don't know what is telling what, where to look for them so I have them all in the src directory:

Whoever comes across this error use the VC development libraries instead of the one for MinGW. For a reason I am not aware of it works.

Related

Problems when linking shared library with GCC [duplicate]

This question already has an answer here:
Libraries in /usr/local/lib not found
(1 answer)
Closed 2 years ago.
I try to link a shared library just installed on my system, but for some reason the output doesn't want to execute. This is my compilation:
gcc -o test test.c -lgpio
When running the output, I get the following error:
./test: error while loading shared libraries: libgpio-3.0.0.so.3: cannot open shared object file: No such file or directory
Which is weird since I have this exact file in my /usr/local/lib-folder (along with libgpio-3.0.0.so and the other shared library files). I don't have much experience with GCC, so can someone please explain what went wrong?
Your library folder is probably not in the default search path. You'll need to specify it using the -L option when you compile:
gcc -L /usr/local/lib-folder -o test test.c -lgpio
You'll also need to add this folder to the LD_LIBRARY_PATH environment variable when you run the program.

Linking local installation of GLFW [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I want to link against a project installed, rather than OS installed, version of GLFW to make my project more portable. I am trying to use both premake and gcc directly but they both fail.
The glfw directory is in project/libraries/glfw-3.2.1
I tried to build glfw by doing:
cd project/libraries/glfw-3.2.1
mkdir bin
cd bin
cmake ..
make all
however I do not see any binary on that directory although I did find the file libglfw3.a
So I tried to build it manually as follows:
g++ main.cpp -I libraries/glfw-3.2.1/include/ -L libraries/glfw-3.2.1/bin/src/libglfw3.a
However that fails to link as none of the glfw objects are found. i.e
I get errors like:
/usr/bin/ld: main.cpp:(.text+0x27): undefined reference to `glfwWindowHint'
try this
g++ main.cpp -I libraries/glfw-3.2.1/include -L libraries/glfw-3.2.1/bin/src -lglfw3
Using -L you are telling the compiler where the library lies but you should use -l to link it

Compiling openGL with GLFW3 program in Ubuntu 15.10 [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I tried building GLFW3 under Ubuntu 15.10 using the tutorial here, and while that seems successful, I can't compile a sample program (provided by GLFW) using the command:
g++ test.cpp -lglfw3 -lGL
I get the following error.
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
/usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I tried including a bunch of different files in the linker, but thes two I have now took away all the other errors except these. I also read that the DSO missing error might indicate the wrong order of linked files, but changing the order doesn't help here. Probably missing some include, but no idea which. If anyone can help, it'd be greatly appreciate. I'm quite new to Linux, so this is beyond my current skills.
You need to get the packages. Run in the right order.
pkg-config --static --libs x11 xrandr xi xxf86vm glew glfw3

SDL2 error messages won't go away

Compile command/what's in the .bat:
g++ -o program.exe SME.cpp -w -Wl -subsystem,windows -lmingw32 -lSDL2main -lSDL2
pause >nul
SME.cpp:
#include "SDL2\SDL.h"
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
I have build.bat, SME.cpp and SDL2.dll in a folder
MinGW is in the default C:\MinGW directory
I installed MinGW using the installer
I added C:\MinGW\include
I put the SDL2 header files in C:\MinGW\include\SDL2\
I put the SDL2 library files (SDL2main.lib and SDL2.lib) in C:\MinGW\lib.
I added C:\MinGW\bin to the Path variable
I've solved all of the previous problems by looking on the internet for answers to them
The compiler keeps complaining that there is an undefined reference to SDL_Init and SDL_Quit and that ld.exe (I have no idea what that is) has returned exit status 1 due to an undefined reference to #WinMain16.
I've searched everywhere and there is a short supply of answers to this problem and all of the answers I've come across haven't worked. I've tried 3 different ways of doing this: with a .bat, with a Makefile and with Eclipse. It always comes down to these three errors. I have no idea what is going wrong, I checked and SDL_init.h and SDL_quit.h both exist. I don't know what #WinMain16 is either.

Undefined reference to PQfinish even though libraries etc. are included [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 8 years ago.
I'm trying to compile a C++ application using libpq.
On my Debian it compiles fine with the following command:
g++ -I /usr/include/postgresql/ -L /usr/lib/postgresql/9.3/lib/ -lpq -o test test.cpp
On my Ubuntu I get the following error:
undefined reference to 'PQfinish'
I've included link to postgresql headers and libraries and used the -lpq. What am I missing?
Move -lpq to the end of the command line.
Linking is done in the order specified, and objects are only taken from libraries if they are needed to resolve symbols at that point. So each library has to come after any other object that needs it.