Error linking with mingw compiler using Codelite, can't find lib folder

5.7k views Asked by At

I'm trying to get started with SDL and trying to compile a 'hello world' starter app to check my configuration and I get this error:

C:/MinGW-4.8.1/bin/g++.exe -c "C:/Users/Me/Documents/Cpp_Projects/Demo_Graphics/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -IC:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/include C:/MinGW-4.8.1/bin/g++.exe -o ./Debug/Demo_Graphics @"Demo_Graphics.txt" -L. -lC:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/ c:/mingw-4.8.1/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lC:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/ collect2.exe: error: ld returned 1 exit status mingw32-make.exe[1]: *** [Debug/Demo_Graphics] Error 1 Demo_Graphics.mk:79: recipe for target 'Debug/Demo_Graphics' failed mingw32-make.exe[1]: Leaving directory 'C:/Users/Me/Documents/Cpp_Projects/Demo_Graphics' mingw32-make.exe: *** [All] Error 2 Makefile:4: recipe for target 'All' failed 1 errors, 0 warnings

The directory C:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/ certainly does exist and has the required SDL libraries in it, but I have no clue about compilers.
This is predefined code which should work so the problem is in set up somewhere?

1

There are 1 answers

1
Julian On BEST ANSWER

The -l compiler flag is adding a library dependency. It does not specify a path in which to look for libraries (that is the -L flag), which appears to be what you are expecting.

In your error message:

-L.  -lC:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/

You can see that the compiler is looking in your current working directory (.) for the library C:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/, but this is not a library -- this is the directory in which you're storing the SDL libraries.

In the CodeLite linker setup you want to change your library path to C:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/, or use

-LC:/Users/Me/Documents/Cpp_Projects/SDL2/32bit/lib/

as a build flag.

You also need to link to the SDL2 library, so you'll need to add -lSDL2 (possibly -lSDL2main as well, I can't remember the specifics of the SDL libraries) to your build/linker flags.