Bad reloc address 0x0 - linking roblem?

dazmon wrote on Saturday, March 01, 2014:

Hello,
I can’t get working libraries in Netbeans (first time i’m using third party library).
Specifically GLEW and GLFW. Also i want to be sure i’m doing things right.

Specifications:
Windows 7 Pro (64bit)
Procesor: Intel I7 3820
GPU: GeForce GTX 660 (2GB GDDR5)

My approach step by step:

  1. Downloaded minGW-64w with manager:
    Settings: Version 4.8.1, Architecture x64, Thread posix, Exception seh and Build revision 5.
    Path of instalation: c:\minGW\minGW64

  2. Downloaded binary of MSYS and extracted to:
    c:\mingw\msys

  3. Added values to system path:
    some-system-path-s;c:\mingw\mingw64\bin;c:\mingw\msys\bin;

-> To this point all should be fine (C++ projects are working and compiling fine).
-> Also Netbeans automatically sets all links in options for C/C++ compiler.

  1. Downloaded source code of GLEW, then i executed “make” (just make without any parametres)
    in folder of GLEW with MSYS and moved content of folder:
    …glew\lib to …/mingw/mingw64\lib
    …glew\include to …/mingw/mingw64\include

  2. Downloaded binary of GLFW and moved content of folder
    …glfw\lib to …/mingw/mingw64\lib
    …glfw\include to …/mingw/mingw64\include

  3. Changed settings of project properties in Netbeans:
    Build->C++ Compiler->General->Include Directories and Headers: …/mingw64/include
    Build->Linker->General->Additional Library Directories: …/mingw/mingw64/lib
    Build->Linker->Libraries: opengl32, glew32 (libglw32.a), glfw3 (libglfw3.a)
    Everything else is default.

Then i’m trying to run code:

            #include <cstdlib>
            #include <stdio.h>
            #include <stdlib.h>
            #include <GL/glew.h>
            #include <GLFW/glfw3.h>

            using namespace std;
            int main(int argc, char** argv) {
                if (!glfwInit()){
                    fprintf(stderr, "Failed to initialize GLFW\n");
                    return -1;
                }
                return 0;
            }

Returns this error:

            "/c/mingw/msys/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-                        conf
            make.exe[1]: Entering directory    `/c/Users/Ruzgud/Documents/NetBeansProjects/LordsAndServants'
            "/c/mingw/msys/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-    Windows/lordsandservants.exe
            make.exe[2]: Entering directory `/c/Users/Ruzgud/Documents/NetBeansProjects/LordsAndServants'
            mkdir -p dist/Debug/MinGW-Windows
            g++     -o dist/Debug/MinGW-Windows/lordsandservants build/Debug/MinGW-Windows/main.o -    L../../../../../mingw/mingw64/lib -lglew32 -lglfw3
            ../../../../../mingw/mingw64/lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x2a7): undefined reference to `__imp_CreateDCW'
            ../../../../../mingw/mingw64/lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x2e9): undefined reference to `__imp_GetDeviceCaps'
            ../../../../../mingw/mingw64/lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x2fb): undefined reference to `__imp_GetDeviceCaps'
            ../../../../../mingw/mingw64/lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x31e): undefined reference to `__imp_DeleteDC'
            c:/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../../../mingw/mingw64/lib/libglfw3.a(win32_monitor.c.obj): bad reloc address     0x0 in section `.pdata'
            collect2.exe: error: ld returned 1 exit status
            make.exe[2]: *** [dist/Debug/MinGW-Windows/lordsandservants.exe] Error 1
            make.exe[2]: Leaving directory `/c/Users/Ruzgud/Documents/NetBeansProjects/LordsAndServants'
            make.exe[1]: *** [.build-conf] Error 2
            make.exe[1]: Leaving directory `/c/Users/Ruzgud/Documents/NetBeansProjects/LordsAndServants'
            make.exe": *** [.build-impl] Error 2

I have also found some topic, but that didn’t help: link

What i have tried so far worth mentioning:

  • Linking and not linking against winmm while compiling glfw,
  • binary files of glfw for 64bit and my own compiled - neither of them worked(both throw same error),
  • different builds of minGW-w64,
  • linkin static and dynamic libraries.

If anyone know solution, then please help. I know i can just simply include source files to project, but i would like to learn how to properly use libraries. English is my second language, so please excuse my mistakes.
Thank you for help.