C++ Compile error

jaywash

Baseband Member
Messages
69
Location
Canada
when i type this code:
Code:
#include <iostream> 
 using namespace std;
int main()
{
 cout << "Hello world!" << endl; 
return 0; 
}
into code::blocks or C++ visual studio 2010 (using the code it generates by default)

i get this error:

||=== Hello World, Debug ===|
ld.exe||cannot find -lSDL_image|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 6 seconds) ===|

can anyone tell me what this means and how i fix it? ive tried uninstalling and reinstalling and it didnt work
 
i am not a programmer at all, but i have had some basics C++ and C# lessons when i was doing my education.

i don't know if this helps, but i think there is suppose to be a space between "int main" and "()"
so try this "int main ()"
 
This is a 'Linker' error, not a compiler error. As such, there is nothing wrong with your code block above. The error you're getting refers to an external resource which your application is attempting to link with called SDL_image.

Linking is the build stage which takes place after compilation. Your code is compiled into individual objects (typically libraries) and then these objects are linked together. Ultimately these will culminate in either static linking which bundle the code directly into the final executable or shared objects (.so on linux) / dynamically linked libraries (.dll on windows) where the executable reads in the libraries as and when required.

I'm guessing you took your starting point from an example project somewhere, by copying that project you've also inherited the linker settings. I don't use visual studio, so I can't give you precise directions for your UI, but I imagine if you right click your project and go to properties - then look for Linker settings - you'll find a reference somewhere to something called libSDL_image.dll or similar. Remove that reference and then try to build your project again.

As a side note, this is one of the problems I find with beginners using 'intelligent' IDEs. They are supposed to make the work easier to do, but ultimately lead to FAR more 'errors' due to their misconfiguration and they'll be much harder to find solutions for. If you can, take any single-file code samples and just run with gcc or other compiler which works outside of an IDE (integrated development environment, i.e. visual studio/eclipse/netbeans etc.). This should make your life much easier in future.

Hope that helps,
Michael.
 
Last edited:
This is a 'Linker' error, not a compiler error. As such, there is nothing wrong with your code block above. The error you're getting refers to an external resource which your application is attempting to link with called SDL_image.

Linking is the build stage which takes place after compilation. Your code is compiled into individual objects (typically libraries) and then these objects are linked together. Ultimately these will culminate in either static linking which bundle the code directly into the final executable or shared objects (.so on linux) / dynamically linked libraries (.dll on windows) where the executable reads in the libraries as and when required.

I'm guessing you took your starting point from an example project somewhere, by copying that project you've also inherited the linker settings. I don't use visual studio, so I can't give you precise directions for your UI, but I imagine if you right click your project and go to properties - then look for Linker settings - you'll find a reference somewhere to something called libSDL_image.dll or similar. Remove that reference and then try to build your project again.

As a side note, this is one of the problems I find with beginners using 'intelligent' IDEs. They are supposed to make the work easier to do, but ultimately lead to FAR more 'errors' due to their misconfiguration and they'll be much harder to find solutions for. If you can, take any single-file code samples and just run with gcc or other compiler which works outside of an IDE (integrated development environment, i.e. visual studio/eclipse/netbeans etc.). This should make your life much easier in future.

Hope that helps,
Michael.

Thanks! :D everything works fine now, I can finally study it properly :) thank you so much.
 
Back
Top Bottom