Author Topic: Project not building after change in its properties  (Read 6434 times)

Offline pion

  • Multiple posting newcomer
  • *
  • Posts: 10
Project not building after change in its properties
« on: September 19, 2021, 12:35:41 pm »
I'm trying to import the SDL2 library and followed these two tutorials:

https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php
https://www.youtube.com/watch?v=QV6bOYbT_-I&t=57s

However, after I changed the project's properties accordingly (add search directory, edit linker options, add library directory etc. ), pasted the code and put the .dll file into the project folder, (it gives me no errors when debugging) it repeatedly asks me if I want to build the project, but won't execute the program or build the project. It only happens after changing the properties, the code seems to be alright.

Code (If it has something to do with it,  taken from the second tutorial link):

Code
#include <iostream>
using namespace std;
#include <SDL2/SDL.h>

int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);
    cout << "Hello" << endl;
    SDL_Window* window;
    window = SDL_CreateWindow("MyWindowTitle", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    640, 480, SDL_WINDOW_RESIZABLE);
    SDL_Delay(4000);
    SDL_DestroyWindow(window);
    SDL_Quit();
}

I would appreciate your help!


Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Project not building after change in its properties
« Reply #1 on: September 19, 2021, 01:30:32 pm »
Post a full rebuild log, see this FAQ (you can get an error from Cloudflare, retry sone times)

Offline pion

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Project not building after change in its properties
« Reply #2 on: September 19, 2021, 02:53:53 pm »
Sorry, no matter how long I try the site doesnt load.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Project not building after change in its properties
« Reply #3 on: September 19, 2021, 07:50:55 pm »
In brief:
   - Open your project
   - Go to Settings -> Compiler -> Other settings and select "Full command line"
   - Select Build -> Rebuild
   - Select the "Build log" tab in the "Logs and others" window (not the "Build messages" one)
   - Right click in the tab and select "Copy contents to clipboard"
   - Paste the contents here using code tags



Offline pion

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Project not building after change in its properties
« Reply #4 on: September 19, 2021, 08:34:51 pm »
Here:

Code

-------------- Clean: Debug in SDL2test (compiler: GNU GCC Compiler)---------------

Cleaned "SDL2test - Debug"

-------------- Build: Debug in SDL2test (compiler: GNU GCC Compiler)---------------

gcc.exe -Wall -g -I..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\include -c C:\Users\lr\Desktop\SDL2\sdl2.c -o obj\Debug\sdl2.o
gcc.exe -L..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib -o bin\Debug\SDL2.exe obj\Debug\sdl2.o  -lmingw32 -lSDL2main -lSDL2 
C:\Users\lr\Desktop\SDL2\sdl2.c: In function 'SDL_main':
C:\Users\lr\Desktop\SDL2\sdl2.c:14:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib\libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.dll.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib\libSDL2.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.dll.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 1 warning(s) (0 minute(s), 1 second(s))
 


Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Project not building after change in its properties
« Reply #5 on: September 20, 2021, 06:35:59 am »
Looks like you are mixing 32 and 64 bit code and libraries.

The tutorial includes the following paragraph that explains which SDL directory contains the 32 bit library and which contains the 64 bit library:

Open the gzip archive and there should be a tar archive. Open up the tar archive and the should be a folder called SDL2-2.something.something. In side of that folder there should be a bunch of folders and files, most importantly i686-w64-mingw32 which contains the 32bit library and x86_64-w64-mingw32 which contains the 64bit library.

You need to use the same 32bit or 64 bit library to match the 32bit or 64 bit Mingw you installed. If you installed the 32bit MINGW you need to use the 32bit SDL2 library or if you installed the 64 bit MINGW then you need to use the 64bit SDL2 library.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Project not building after change in its properties
« Reply #6 on: September 20, 2021, 09:31:34 am »
Or use the -m32 or -m64 flag when compiling...

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Project not building after change in its properties
« Reply #7 on: September 20, 2021, 03:58:52 pm »
Or use the -m32 or -m64 flag when compiling...

There is not a great chance on Windows of having a GCC MinGW compiler that really works well with the -m32 or -m64 flags.
This is because the builders do not tend to make the C++ libraries for both 32 and 64 bit use.
I have no idea if they make the C libraries for both 32 and 64 bit use.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline pion

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Project not building after change in its properties
« Reply #8 on: September 20, 2021, 07:05:10 pm »
Hello again, thanks for the advice. I followed this tutorial: https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php and tried both, the 32 bit version and the 64 bit version, I also tried the compiler flags. Unfortunately, it still doesnt work.
The rebuild log looks better now, but it still shows a sort of error:

Code
-------------- Clean: Debug in SDL2Testproject (compiler: GNU GCC Compiler)---------------

Cleaned "SDL2Testproject - Debug"

-------------- Build: Debug in SDL2Testproject (compiler: GNU GCC Compiler)---------------

Linking stage skipped (build target has no object files to link)
Nothing to be done (all items are up-to-date).


This time I used this code (from https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php):

Code
/*This source code copyrighted by Lazy Foo' Productions (2004-2020)
and may not be redistributed without written permission.*/

//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;

//The surface contained by the window
SDL_Surface* screenSurface = NULL;

//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );

//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );

//Update the surface
SDL_UpdateWindowSurface( window );

//Wait two seconds
SDL_Delay( 2000 );
}
}

//Destroy window
SDL_DestroyWindow( window );

//Quit SDL subsystems
SDL_Quit();

return 0;
}


Could it have something to do with the Path variable? Or with the inclusion of the header file? I've seen people mention that on other posts.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Project not building after change in its properties
« Reply #9 on: September 20, 2021, 07:26:32 pm »
You have created a new project, did you add the new source file to it?

Offline pion

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Project not building after change in its properties
« Reply #10 on: September 20, 2021, 08:40:56 pm »
Sometimes you forget the simplest things! Thanks a lot! It works fine now :)