Author Topic: Unable to Compile a Simple Program\Linker Errors  (Read 20055 times)

Offline Spirrwell

  • Multiple posting newcomer
  • *
  • Posts: 11
Unable to Compile a Simple Program\Linker Errors
« on: February 03, 2013, 04:00:38 am »
Alright, I recently downgraded back to Vista from 7, (alright, laugh it up) and I installed Code::Blocks 12.11. Now I have had absolutely no problems in the past and all I have is a simple SDL 2.0 program that initializes SDL and quits. I've linked to the appropriate SDL2main and SDL2 libraries, (in the proper order) and it just refuses to compile and I get some odd linker errors. I even tried downloading the latest of MinGW and that didn't work. I've read up on the problem and people keep saying to link to winmm which I've never had to do, but it doesn't work anyway. I'll also mention that this happens regardless of whether I use SDL 2.0 or SDL 1.2. This also happens with other libraries as well. I get those classic "undefined reference to BLABLA" errors.

I don't have any of these problems when doing the same on Ubuntu 12.04 64 bit. It just works so well, but I can't just develop for Linux. (well I could, but that limits my options)

Just for the sake of things, here's my code:

Code
#include <SDL.h>

int main(int argc, char* argv[])
{
    if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
    {
        printf("%s\n", SDL_GetError);
        exit(EXIT_FAILURE);
    }
    atexit(SDL_Quit);
    return 0;
}

And here's all of my build messages:

Code
||=== SDL2, Debug ===|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_systimer.o)||In function `SDL_StartTicks':|
c:\SDL-2.0.0-6799\src\timer\windows\SDL_systimer.c|59|undefined reference to `timeBeginPeriod@4'|
c:\SDL-2.0.0-6799\src\timer\windows\SDL_systimer.c|60|undefined reference to `timeGetTime@0'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_systimer.o)||In function `SDL_GetTicks':|
c:\SDL-2.0.0-6799\src\timer\windows\SDL_systimer.c|85|undefined reference to `timeGetTime@0'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowswindow.o)||In function `WIN_SetWindowGammaRamp':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|511|undefined reference to `CreateDCW@16'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|513|undefined reference to `SetDeviceGammaRamp@8'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|517|undefined reference to `DeleteDC@4'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|517|undefined reference to `DeleteDC@4'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowswindow.o)||In function `WIN_GetWindowGammaRamp':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|530|undefined reference to `CreateDCW@16'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|532|undefined reference to `GetDeviceGammaRamp@8'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|536|undefined reference to `DeleteDC@4'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowswindow.c|536|undefined reference to `DeleteDC@4'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o)||In function `WINMM_CloseDevice':|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|166|undefined reference to `waveInClose@4'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|171|undefined reference to `waveOutClose@4'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|178|undefined reference to `waveOutUnprepareHeader@12'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|178|undefined reference to `waveOutUnprepareHeader@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o)||In function `WINMM_PlayDevice':|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|129|undefined reference to `waveOutWrite@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o)||In function `DetectWaveOutDevs':|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|51|undefined reference to `waveOutGetNumDevs@0'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|51|undefined reference to `waveOutGetDevCapsW@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o)||In function `DetectWaveInDevs':|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|52|undefined reference to `waveInGetNumDevs@0'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|52|undefined reference to `waveInGetDevCapsW@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o)||In function `WINMM_OpenDevice':|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|209|undefined reference to `waveInGetNumDevs@0'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|212|undefined reference to `waveInGetDevCapsW@12'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|222|undefined reference to `waveOutGetNumDevs@0'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|225|undefined reference to `waveOutGetDevCapsW@12'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|301|undefined reference to `waveInOpen@24'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|355|undefined reference to `waveOutPrepareHeader@12'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|355|undefined reference to `waveOutPrepareHeader@12'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|305|undefined reference to `waveOutOpen@24'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o)||In function `SetMMerror':|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|104|undefined reference to `waveOutGetErrorTextW@12'|
c:\SDL-2.0.0-6799\src\audio\winmm\SDL_winmm.c|104|undefined reference to `waveOutGetErrorTextW@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_mmjoystick.o)||In function `SDL_SYS_JoystickInit':|
c:\SDL-2.0.0-6799\src\joystick\windows\SDL_mmjoystick.c|162|undefined reference to `joyGetNumDevs@0'|
c:\SDL-2.0.0-6799\src\joystick\windows\SDL_mmjoystick.c|167|undefined reference to `joyGetPosEx@8'|
c:\SDL-2.0.0-6799\src\joystick\windows\SDL_mmjoystick.c|169|undefined reference to `joyGetDevCapsW@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_mmjoystick.o)||In function `SDL_SYS_JoystickUpdate':|
c:\SDL-2.0.0-6799\src\joystick\windows\SDL_mmjoystick.c|328|undefined reference to `joyGetPosEx@8'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windows.o)||In function `WIN_CoInitialize':|
c:\SDL-2.0.0-6799\src\core\windows\SDL_windows.c|47|undefined reference to `CoInitialize@4'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windows.o)||In function `WIN_CoUninitialize':|
c:\SDL-2.0.0-6799\src\core\windows\SDL_windows.c|61|undefined reference to `CoUninitialize@0'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o)||In function `WIN_GL_ChoosePixelFormatARB':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsopengl.c|399|undefined reference to `ChoosePixelFormat@8'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsopengl.c|399|undefined reference to `SetPixelFormat@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o)||In function `WIN_GL_SetupWindow':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsopengl.c|518|undefined reference to `SetPixelFormat@12'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o)||In function `WIN_GL_ChoosePixelFormat':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsopengl.c|206|undefined reference to `DescribePixelFormat@16'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsopengl.c|210|undefined reference to `DescribePixelFormat@16'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o)||In function `WIN_GL_SwapWindow':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsopengl.c|668|undefined reference to `SwapBuffers@4'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsmodes.o)||In function `WIN_GetDisplayMode':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsmodes.c|62|undefined reference to `CreateDCW@16'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsmodes.c|71|undefined reference to `CreateCompatibleBitmap@12'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsmodes.c|72|undefined reference to `GetDIBits@28'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsmodes.c|73|undefined reference to `GetDIBits@28'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsmodes.c|74|undefined reference to `DeleteObject@4'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsmodes.c|75|undefined reference to `DeleteDC@4'|
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsframebuffer.o)||In function `WIN_CreateWindowFramebuffer':|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsframebuffer.c|36|undefined reference to `DeleteDC@4'|
c:\SDL-2.0.0-6799\src\video\windows\SDL_windowsframebuffer.c|39|undefined reference to `DeleteObject@4'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings (0 minutes, 1 seconds) ===|

I've asked on other forums thinking that it's a problem with SDL, but I've tried other libraries and they seem to get their own linker errors as well. I did a quick browse through the forums and didn't find anything that helped. If there's some log file that I'm supposed to post to go with this, sorry I just got here and this is bugging the heck out of me.

Also I am aware of rule number two:

Quote
2. Compiler/Linker errors are NOT Code::Blocks errors. Usually, C++ newcomers tend to confuse the Editor/IDE (Code::Blocks) with the Compiler (MINGW / GCC). You may see some errors in the compiler output because you missed to do something right in your code. But that's not Code::Blocks troubleshooting, that's C++ troubleshooting and does not belong in here. If your program doesn't compile, READ THE C++ MANUAL.

This problem seems to be Code::Blocks specific, and perhaps there's a setting that isn't quite right, but I've just done exactly what I've done in the past and for whatever reason I'm having this problem.

Well, any help is greatly appreciated!

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #1 on: February 03, 2013, 10:48:05 am »
Can you post the full commandline sent to the linker (from "Build log" tab not from "Buil messages").
A short web-search tells me, that you probably miss at least gdi32 in link libraries list.

Offline Spirrwell

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #2 on: February 03, 2013, 02:04:18 pm »
Can you post the full commandline sent to the linker (from "Build log" tab not from "Buil messages").
A short web-search tells me, that you probably miss at least gdi32 in link libraries list.


Sure:
Code
-------------- Build: Debug in SDL2 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe  -o bin\Debug\SDL2.exe obj\Debug\Main.o   -lmingw32 -lOpenGL32  "..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2main.a" "..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a"
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_systimer.o): In function `SDL_StartTicks':
c:\SDL-2.0.0-6799/src/timer/windows/SDL_systimer.c:59: undefined reference to `timeBeginPeriod@4'
c:\SDL-2.0.0-6799/src/timer/windows/SDL_systimer.c:60: undefined reference to `timeGetTime@0'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks':
c:\SDL-2.0.0-6799/src/timer/windows/SDL_systimer.c:85: undefined reference to `timeGetTime@0'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowswindow.o): In function `WIN_SetWindowGammaRamp':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:511: undefined reference to `CreateDCW@16'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:513: undefined reference to `SetDeviceGammaRamp@8'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:517: undefined reference to `DeleteDC@4'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:517: undefined reference to `DeleteDC@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowswindow.o): In function `WIN_GetWindowGammaRamp':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:530: undefined reference to `CreateDCW@16'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:532: undefined reference to `GetDeviceGammaRamp@8'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:536: undefined reference to `DeleteDC@4'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowswindow.c:536: undefined reference to `DeleteDC@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o): In function `WINMM_CloseDevice':
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:166: undefined reference to `waveInClose@4'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:171: undefined reference to `waveOutClose@4'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:178: undefined reference to `waveOutUnprepareHeader@12'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:178: undefined reference to `waveOutUnprepareHeader@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o): In function `WINMM_PlayDevice':
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:129: undefined reference to `waveOutWrite@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o): In function `DetectWaveOutDevs':
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:51: undefined reference to `waveOutGetNumDevs@0'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:51: undefined reference to `waveOutGetDevCapsW@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o): In function `DetectWaveInDevs':
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:52: undefined reference to `waveInGetNumDevs@0'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:52: undefined reference to `waveInGetDevCapsW@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o): In function `WINMM_OpenDevice':
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:209: undefined reference to `waveInGetNumDevs@0'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:212: undefined reference to `waveInGetDevCapsW@12'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:222: undefined reference to `waveOutGetNumDevs@0'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:225: undefined reference to `waveOutGetDevCapsW@12'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:301: undefined reference to `waveInOpen@24'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:355: undefined reference to `waveOutPrepareHeader@12'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:355: undefined reference to `waveOutPrepareHeader@12'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:305: undefined reference to `waveOutOpen@24'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_winmm.o): In function `SetMMerror':
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:104: undefined reference to `waveOutGetErrorTextW@12'
c:\SDL-2.0.0-6799/src/audio/winmm/SDL_winmm.c:104: undefined reference to `waveOutGetErrorTextW@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_mmjoystick.o): In function `SDL_SYS_JoystickInit':
c:\SDL-2.0.0-6799/src/joystick/windows/SDL_mmjoystick.c:162: undefined reference to `joyGetNumDevs@0'
c:\SDL-2.0.0-6799/src/joystick/windows/SDL_mmjoystick.c:167: undefined reference to `joyGetPosEx@8'
c:\SDL-2.0.0-6799/src/joystick/windows/SDL_mmjoystick.c:169: undefined reference to `joyGetDevCapsW@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_mmjoystick.o): In function `SDL_SYS_JoystickUpdate':
c:\SDL-2.0.0-6799/src/joystick/windows/SDL_mmjoystick.c:328: undefined reference to `joyGetPosEx@8'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windows.o): In function `WIN_CoInitialize':
c:\SDL-2.0.0-6799/src/core/windows/SDL_windows.c:47: undefined reference to `CoInitialize@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windows.o): In function `WIN_CoUninitialize':
c:\SDL-2.0.0-6799/src/core/windows/SDL_windows.c:61: undefined reference to `CoUninitialize@0'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_ChoosePixelFormatARB':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsopengl.c:399: undefined reference to `ChoosePixelFormat@8'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsopengl.c:399: undefined reference to `SetPixelFormat@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_SetupWindow':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsopengl.c:518: undefined reference to `SetPixelFormat@12'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_ChoosePixelFormat':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsopengl.c:206: undefined reference to `DescribePixelFormat@16'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsopengl.c:210: undefined reference to `DescribePixelFormat@16'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_SwapWindow':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsopengl.c:668: undefined reference to `SwapBuffers@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsmodes.o): In function `WIN_GetDisplayMode':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsmodes.c:62: undefined reference to `CreateDCW@16'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsmodes.c:71: undefined reference to `CreateCompatibleBitmap@12'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsmodes.c:72: undefined reference to `GetDIBits@28'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsmodes.c:73: undefined reference to `GetDIBits@28'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsmodes.c:74: undefined reference to `DeleteObject@4'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsmodes.c:75: undefined reference to `DeleteDC@4'
..\..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\libSDL2.a(SDL_windowsframebuffer.o): In function `WIN_CreateWindowFramebuffer':
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsframebuffer.c:36: undefined reference to `DeleteDC@4'
c:\SDL-2.0.0-6799/src/video/windows/SDL_windowsframebuffer.c:39: undefined reference to `DeleteObject@4'
Process terminated with status 1 (0 minutes, 1 seconds)
50 errors, 0 warnings (0 minutes, 1 seconds)
 

It doesn't look too different. I even tried linking gdi32 explicitly and that had no effect. I shouldn't have to link any other libraries. At this point with this program all I should have to link to mingw32, SDL2main, and SDL2. That's how I've always built SDL programs. I shouldn't even have to link to OpenGL yet, but I tried that anyway and it had no effect.

Although, I did try this with the new Orwell Dev-C++ and it seemed like I was getting the same errors. So I'm guessing the problem (like I did originally on the SDL forums) is that SDL didn't build properly when I compiled it with MinGW | MSYS. But again I've always compiled it in the same way, and my original reason was to compile SDL 1.2 by configuring it using --disable-stdio-redirect, but for SDL 2.0 there are no binaries so I have to compile it from source anyway. The binary for SDL 1.2 on SDL's website doesn't contain libSDL.a, just libSDLmain.a so I can't test it.

I could get the binaries for VS2010 (SDL 1.2) working, but I can't stand VC++ and I can't get SDL 2.0 to compile under VC++ anyway which is what I want to use because of its zlib license. I'm sorry that it appears that this an SDL\MinGW\MSYS specific question now. I've just gone through three forums now with no answer.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #3 on: February 03, 2013, 02:49:29 pm »
At this point with this program all I should have to link to mingw32, SDL2main, and SDL2. That's how I've always built SDL programs.
Are you sure you're linking to the correct SDL2?
Because you're linking to the static library and most of the time SDL comes as dynamic lib.
Keep in mind that static libraries don't handle dependencies, so you'll have to link you project to all libraries required by the static lib you're linking.

p.s. also it is better to specify SDL2main and SDL in the linker settings, instead of the full paths you're using.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Spirrwell

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #4 on: February 03, 2013, 04:02:10 pm »
At this point with this program all I should have to link to mingw32, SDL2main, and SDL2. That's how I've always built SDL programs.
Are you sure you're linking to the correct SDL2?
Because you're linking to the static library and most of the time SDL comes as dynamic lib.
Keep in mind that static libraries don't handle dependencies, so you'll have to link you project to all libraries required by the static lib you're linking.

p.s. also it is better to specify SDL2main and SDL in the linker settings, instead of the full paths you're using.
Actually it doesn't matter whether or not I link statically or if I use the simple -lSDL2main and -lSDL2 in Other Linker Options. I still have the same problem either way. The reason I would use the full paths is to link statically, and it was the only way I found that it worked, at least under Ubuntu it worked just fine.

What I don't understand is why the errors are showing up in files that are in my C:\SDL-2.0.0-6799 directory. All I do is copy the includes and libs to the C:\Program Files (x86)\CodeBlocks\MinGW folder to make it simpler, I've never had errors like this before.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #5 on: February 03, 2013, 04:24:08 pm »
What I don't understand is why the errors are showing up in files that are in my C:\SDL-2.0.0-6799 directory. All I do is copy the includes and libs to the C:\Program Files (x86)\CodeBlocks\MinGW folder to make it simpler, I've never had errors like this before.

I've told you why, but you've skipped it, so I repeat:
Keep in mind that static libraries don't handle dependencies, so you'll have to link you project to all libraries required by the static lib you're linking.

Please read more about linking to static libraries, because it seems you have very little knowledge about it or about linking in general. And it is not a simple matter.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Spirrwell

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #6 on: February 03, 2013, 05:55:34 pm »
What I don't understand is why the errors are showing up in files that are in my C:\SDL-2.0.0-6799 directory. All I do is copy the includes and libs to the C:\Program Files (x86)\CodeBlocks\MinGW folder to make it simpler, I've never had errors like this before.

I've told you why, but you've skipped it, so I repeat:
Keep in mind that static libraries don't handle dependencies, so you'll have to link you project to all libraries required by the static lib you're linking.

Please read more about linking to static libraries, because it seems you have very little knowledge about it or about linking in general. And it is not a simple matter.
And so I'll repeat, it doesn't matter whether or not I link statically or dynamically, the same errors occur. Which is why I was wondering why it was doing that. Logically if I link like normal with -lSDL2main and -lSDL2, it should do things automatically and complain about not having SDL2.dll if it's not the same directory. But it's giving me these errors which I never got under Windows 7 or Ubuntu.

I mean here it is:



It's what I've usually done in the past and stick the .dll file in the appropriate folder.

Here's the output when dynamically linking it:

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

Cleaned "SDL2 - Debug"

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

mingw32-g++.exe -Wall  -g     -c C:\Users\Spirrwell\Documents\CodeBlocks\Projects\SDL2\Main.cpp -o obj\Debug\Main.o
mingw32-g++.exe  -o bin\Debug\SDL2.exe obj\Debug\Main.o   -lmingw32 -lOpenGL32 -lSDL2main -lSDL2 
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_systimer.o): In function `SDL_StartTicks':
c:\SDL-2.0.0\buildsdl2/../src/timer/windows/SDL_systimer.c:59: undefined reference to `timeBeginPeriod@4'
c:\SDL-2.0.0\buildsdl2/../src/timer/windows/SDL_systimer.c:60: undefined reference to `timeGetTime@0'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks':
c:\SDL-2.0.0\buildsdl2/../src/timer/windows/SDL_systimer.c:85: undefined reference to `timeGetTime@0'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowswindow.o): In function `WIN_SetWindowGammaRamp':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:511: undefined reference to `CreateDCW@16'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:513: undefined reference to `SetDeviceGammaRamp@8'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:517: undefined reference to `DeleteDC@4'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:517: undefined reference to `DeleteDC@4'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowswindow.o): In function `WIN_GetWindowGammaRamp':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:530: undefined reference to `CreateDCW@16'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:532: undefined reference to `GetDeviceGammaRamp@8'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:536: undefined reference to `DeleteDC@4'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowswindow.c:536: undefined reference to `DeleteDC@4'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_winmm.o): In function `WINMM_CloseDevice':
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:166: undefined reference to `waveInClose@4'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:171: undefined reference to `waveOutClose@4'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:178: undefined reference to `waveOutUnprepareHeader@12'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:178: undefined reference to `waveOutUnprepareHeader@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_winmm.o): In function `WINMM_PlayDevice':
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:129: undefined reference to `waveOutWrite@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_winmm.o): In function `DetectWaveOutDevs':
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:51: undefined reference to `waveOutGetNumDevs@0'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:51: undefined reference to `waveOutGetDevCapsW@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_winmm.o): In function `DetectWaveInDevs':
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:52: undefined reference to `waveInGetNumDevs@0'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:52: undefined reference to `waveInGetDevCapsW@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_winmm.o): In function `WINMM_OpenDevice':
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:209: undefined reference to `waveInGetNumDevs@0'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:212: undefined reference to `waveInGetDevCapsW@12'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:222: undefined reference to `waveOutGetNumDevs@0'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:225: undefined reference to `waveOutGetDevCapsW@12'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:301: undefined reference to `waveInOpen@24'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:355: undefined reference to `waveOutPrepareHeader@12'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:355: undefined reference to `waveOutPrepareHeader@12'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:305: undefined reference to `waveOutOpen@24'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_winmm.o): In function `SetMMerror':
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:104: undefined reference to `waveOutGetErrorTextW@12'
c:\SDL-2.0.0\buildsdl2/../src/audio/winmm/SDL_winmm.c:104: undefined reference to `waveOutGetErrorTextW@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_mmjoystick.o): In function `SDL_SYS_JoystickInit':
c:\SDL-2.0.0\buildsdl2/../src/joystick/windows/SDL_mmjoystick.c:162: undefined reference to `joyGetNumDevs@0'
c:\SDL-2.0.0\buildsdl2/../src/joystick/windows/SDL_mmjoystick.c:167: undefined reference to `joyGetPosEx@8'
c:\SDL-2.0.0\buildsdl2/../src/joystick/windows/SDL_mmjoystick.c:169: undefined reference to `joyGetDevCapsW@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_mmjoystick.o): In function `SDL_SYS_JoystickUpdate':
c:\SDL-2.0.0\buildsdl2/../src/joystick/windows/SDL_mmjoystick.c:328: undefined reference to `joyGetPosEx@8'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windows.o): In function `WIN_CoInitialize':
c:\SDL-2.0.0\buildsdl2/../src/core/windows/SDL_windows.c:47: undefined reference to `CoInitialize@4'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windows.o): In function `WIN_CoUninitialize':
c:\SDL-2.0.0\buildsdl2/../src/core/windows/SDL_windows.c:61: undefined reference to `CoUninitialize@0'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_ChoosePixelFormatARB':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsopengl.c:399: undefined reference to `ChoosePixelFormat@8'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsopengl.c:399: undefined reference to `SetPixelFormat@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_SetupWindow':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsopengl.c:518: undefined reference to `SetPixelFormat@12'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_ChoosePixelFormat':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsopengl.c:206: undefined reference to `DescribePixelFormat@16'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsopengl.c:210: undefined reference to `DescribePixelFormat@16'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowsopengl.o): In function `WIN_GL_SwapWindow':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsopengl.c:668: undefined reference to `SwapBuffers@4'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowsmodes.o): In function `WIN_GetDisplayMode':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsmodes.c:62: undefined reference to `CreateDCW@16'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsmodes.c:71: undefined reference to `CreateCompatibleBitmap@12'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsmodes.c:72: undefined reference to `GetDIBits@28'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsmodes.c:73: undefined reference to `GetDIBits@28'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsmodes.c:74: undefined reference to `DeleteObject@4'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsmodes.c:75: undefined reference to `DeleteDC@4'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../libSDL2.a(SDL_windowsframebuffer.o): In function `WIN_CreateWindowFramebuffer':
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsframebuffer.c:36: undefined reference to `DeleteDC@4'
c:\SDL-2.0.0\buildsdl2/../src/video/windows/SDL_windowsframebuffer.c:39: undefined reference to `DeleteObject@4'
Process terminated with status 1 (0 minutes, 1 seconds)
50 errors, 0 warnings (0 minutes, 1 seconds)
 

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #7 on: February 03, 2013, 06:46:18 pm »
Using -lSDL doesn't mean you link dynamically to libSDK, but it is just the proper way to specify libraries.
What matters is what the linker finds, if it finds a static library it links to it.
So you'll have to make sure you have SDL.dlll in the folders, where the linker searches for them or otherwise you'll have to link in your project to all the libraries SDL depends on.
I'm not sure if the linker will choose the dll if there are both static and dynamic libs in the same folder.
For this you'll have to inspect the manual of gcc/ld.
Which is a pretty good idea anyway, you'll learn a lot of things (hint read what -l and -L does in the manual of GCC) :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Spirrwell

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Unable to Compile a Simple Program\Linker Errors
« Reply #8 on: February 10, 2013, 07:16:09 pm »
Alrighty, I figured it out, SDL 2.0 wasn't building the shared libraries because it was MinGW or the SDL configuration that was looking in the wrong directory for its own object files. Odd, but I got it built and it works now.