2013-07-18 14 views
5

Próbuję skompilować przykład z dokumentacji GLFW.Potrzebuję pomocy, próbując skompilować prosty przykład dla GLFW z MinGW

Moja struktura folderu dla bibliotek i plików źródłowych są:

C: \ CPP \

glfw3.dll glfw3dll.a libglfw3.a test.cpp

zawierać \

GLFW \

glfw3.h glfw3native.h

#include <GLFW/glfw3.h> 

int main(void) 
{ 
    GLFWwindow* window; 

    /* Initialize the library */ 
    if (!glfwInit()) 
     return -1; 

    /* Create a windowed mode window and its OpenGL context */ 
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); 
    if (!window) 
    { 
     glfwTerminate(); 
     return -1; 
    } 

    /* Make the window's context current */ 
    glfwMakeContextCurrent(window); 

    /* Loop until the user closes the window */ 
    while (!glfwWindowShouldClose(window)) 
    { 
     /* Render here */ 

     /* Swap front and back buffers */ 
     glfwSwapBuffers(window); 

     /* Poll for and process events */ 
     glfwPollEvents(); 
    } 

    glfwTerminate(); 
    return 0; 
} 

Próbuję skompilować go poleceniem

c:\cpp>x86_64-w64-mingw32-g++ -lglfw3 -Iinclude test.cpp -o test 

ale otrzymuję ten błąd: wyjścia

c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglfw3 collect2.exe: error: ld returned 1 exit status 

-v:

Using built-in specs. 
COLLECT_GCC=x86_64-w64-mingw32-g++ 
COLLECT_LTO_WRAPPER=c:/users/username/gcc/bin/../libexec/gcc/x86_64-w64-ming 
w32/4.7.2/lto-wrapper.exe 
Target: x86_64-w64-mingw32 
Configured with: ../gcc-4.7.2-mingw/configure --host=x86_64-w64-mingw32 --build= 
x86_64-unknown-linux-gnu --target=x86_64-w64-mingw32 --prefix=/home/gfortran/gcc 
-home/binary/mingw32/native/x86_64/gcc/4.7.2 --with-sysroot=/home/gfortran/gcc-h 
ome/binary/mingw32/cross/x86_64/gcc/4.7.2 --with-gcc --with-gnu-ld --with-gnu-as 
--with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_64/gmp --with-mpfr 
=/home/gfortran/gcc-home/binary/mingw32/native/x86_64/mpfr --with-mpc=/home/gfor 
tran/gcc-home/binary/mingw32/native/x86_64/mpc --with-cloog=/home/gfortran/gcc-h 
ome/binary/mingw32/native/x86_64/cloog --with-ppl=/home/gfortran/gcc-home/binary 
/mingw32/native/x86_64/ppl --with-host-libstdcxx='-lstdc++ -lsupc++ -lm' --enabl 
e-cloog-backend=ppl --enable-targets=i686-w64-mingw32,x86_64-w64-mingw32 --enabl 
e-lto --enable-languages=c,c++,fortran --enable-libgomp --enable-threads=win32 - 
-enable-static --enable-shared=lto-plugin --enable-plugins --enable-ld=yes --ena 
ble-libquadmath --enable-libquadmath-support --disable-nls --disable-tls --disab 
le-win32-registry 
Thread model: win32 
gcc version 4.7.2 (GCC) 
COLLECT_GCC_OPTIONS='-I' 'include' '-o' 'test.exe' '-v' '-mtune=generic' '-march 
=x86-64' 
c:/users/username/gcc/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.2/cc1plus.e 
xe -quiet -v -I include -iprefix c:\users\username\gcc\bin\../lib/gcc/x86_64 
-w64-mingw32/4.7.2/ -U_REENTRANT test.cpp -quiet -dumpbase test.cpp -mtune=gener 
ic -march=x86-64 -auxbase test -version -o C:\Users\username~1.ADM\AppData\Local\T 
emp\ccfe85gV.s 
GNU C++ (GCC) version 4.7.2 (x86_64-w64-mingw32) 
     compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.0.0, 
MPC version 0.9 
warning: GMP header version 5.0.5 differs from library version 5.0.1. 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
ignoring duplicate directory "c:/users/username/gcc/lib/gcc/../../lib/gcc/x8 
6_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2" 
ignoring duplicate directory "c:/users/username/gcc/lib/gcc/../../lib/gcc/x8 
6_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/x86_64-w64-mingw32" 
ignoring duplicate directory "c:/users/username/gcc/lib/gcc/../../lib/gcc/x8 
6_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/backward" 
ignoring duplicate directory "c:/users/username/gcc/lib/gcc/../../lib/gcc/x8 
6_64-w64-mingw32/4.7.2/include" 
ignoring nonexistent directory "/home/gfortran/gcc-home/binary/mingw32/cross/x86 
_64/gcc/4.7.2/home/gfortran/gcc-home/binary/mingw32/native/x86_64/gcc/4.7.2/lib/ 
gcc/x86_64-w64-mingw32/4.7.2/../../../../include" 
ignoring duplicate directory "c:/users/username/gcc/lib/gcc/../../lib/gcc/x8 
6_64-w64-mingw32/4.7.2/include-fixed" 
ignoring duplicate directory "c:/users/username/gcc/lib/gcc/../../lib/gcc/x8 
6_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/include" 
ignoring nonexistent directory "/home/gfortran/gcc-home/binary/mingw32/cross/x86 
_64/gcc/4.7.2/mingw/include" 
#include "..." search starts here: 
#include <...> search starts here: 
include 
c:\users\username\gcc\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../i 
nclude/c++/4.7.2 
c:\users\username\gcc\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../i 
nclude/c++/4.7.2/x86_64-w64-mingw32 
c:\users\username\gcc\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../i 
nclude/c++/4.7.2/backward 
c:\users\username\gcc\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include 
c:\users\username\gcc\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/include-fixed 

c:\users\username\gcc\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x 
86_64-w64-mingw32/include 
End of search list. 
GNU C++ (GCC) version 4.7.2 (x86_64-w64-mingw32) 
     compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.0.0, 
MPC version 0.9 
warning: GMP header version 5.0.5 differs from library version 5.0.1. 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
Compiler executable checksum: 0b3cd9e378660c38a8a80567400ff92f 
COLLECT_GCC_OPTIONS='-I' 'include' '-o' 'test.exe' '-v' '-mtune=generic' '-march 
=x86-64' 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x 
86_64-w64-mingw32/bin/as.exe -v -I include -o C:\Users\username~1.ADM\AppData\Loca 
l\Temp\ccQqklHV.o C:\Users\username~1.ADM\AppData\Local\Temp\ccfe85gV.s 
GNU assembler version 2.22.52 (x86_64-w64-mingw32) using BFD version (GNU Binuti 
ls) 2.22.52.20120723 
COMPILER_PATH=c:/users/username/gcc/bin/../libexec/gcc/x86_64-w64-mingw32/4. 
7.2/;c:/users/username/gcc/bin/../libexec/gcc/;c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ 
EQ_LIBRARY_PATH=c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7. 
2/;c:/users/username/gcc/bin/../lib/gcc/;C:/Users/username/gcc/x86_64-w6 
4-mingw32/lib/../lib/;c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw3 
2/4.7.2/../../../../x86_64-w64-mingw32/lib/../lib/;c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../lib/;C:/Users/username/gcc/ 
x86_64-w64-mingw32/lib/;c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-ming 
w32/4.7.2/../../../../x86_64-w64-mingw32/lib/;c:/users/username/gcc/bin/../l 
ib/gcc/x86_64-w64-mingw32/4.7.2/../../../ 
COLLECT_GCC_OPTIONS='-I' 'include' '-o' 'test.exe' '-v' '-mtune=generic' '-march 
=x86-64' 
c:/users/username/gcc/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.2/collect2. 
exe --sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_64/gcc/4.7.2 -m i 
386pep -Bdynamic -o test.exe C:/Users/username/gcc/x86_64-w64-mingw32/lib/.. 
/lib/crt2.o C:/Users/username/gcc/x86_64-w64-mingw32/lib/../lib/crtbegin.o - 
Lc:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2 -Lc:/users/ 
username/gcc/bin/../lib/gcc -LC:/Users/username/gcc/x86_64-w64-mingw32/lib 
/../lib -Lc:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../. 
./../../x86_64-w64-mingw32/lib/../lib -Lc:/users/username/gcc/bin/../lib/gcc 
/x86_64-w64-mingw32/4.7.2/../../../../lib -LC:/Users/username/gcc/x86_64-w64 
-mingw32/lib -Lc:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2 
/../../../../x86_64-w64-mingw32/lib -Lc:/users/username/gcc/bin/../lib/gcc/x 
86_64-w64-mingw32/4.7.2/../../.. C:\Users\username~1.ADM\AppData\Local\Temp\ccQqkl 
HV.o -lglfw3 -lstdc++ -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 - 
lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt C:/Us 
ers/username/gcc/x86_64-w64-mingw32/lib/../lib/crtend.o 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../lib/libglfw3.a when searching f 
or -lglfw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../lib/glfw3.dll when searching fo 
r -lglfw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../lib\libglfw3.a when searching f 
or -lglfw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../libglfw3.a when searching for -lgl 
fw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../glfw3.dll when searching for -lglf 
w3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../..\libglfw3.a when searching for -lgl 
fw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../lib/libglfw3.a when searching f 
or -lglfw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../lib/glfw3.dll when searching fo 
r -lglfw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../libglfw3.a when searching for -lgl 
fw3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/users/username/gcc/bin 
/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../glfw3.dll when searching for -lglf 
w3 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: cannot find -lglfw3 
collect2.exe: error: ld returned 1 exit status 

c: \ cpp> x86_64-w64-mingw32-g ++ -Zawiera test.cpp -o test. \ glfw3.dll

c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `.\glfw3.dll' is in 
compatible with i386:x86-64 output 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0xe): undefi 
ned reference to `glfwInit' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x43): undef 
ined reference to `glfwCreateWindow' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x53): undef 
ined reference to `glfwTerminate' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x66): undef 
ined reference to `glfwMakeContextCurrent' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x74): undef 
ined reference to `glfwSwapBuffers' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x79): undef 
ined reference to `glfwPollEvents' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x85): undef 
ined reference to `glfwWindowShouldClose' 
C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o:test.cpp:(.text+0x93): undef 
ined reference to `glfwTerminate' 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: C:\Users\username~1.ADM\AppData\Local\Temp\cceVroaP.o 
: bad reloc address 0x0 in section `.pdata' 
c:/users/username/gcc/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x8 
6_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation 
collect2.exe: error: ld returned 1 exit status 

Odpowiedz

2

Kolejność, w jakiej znajduje się biblioteka w linii komend jest ważna dla gcc oraz ścieżek przeszukiwania biblioteki. Spróbuj przenieść -lglfw3 na koniec i dodaj bieżący katalog do ścieżki wyszukiwania, używając -L.

np.

g++ -Iinclude test.cpp -o test.exe -L . -lglfw3 

Edit1: Od patrząc na wyjściu stanu opisowym, wydaje libglfw3.a że masz nie jest kompatybilny z gcc mingw używasz. Na szczęście linker ld może pracować z plikami DLL bezpośrednio. Zobacz, czy następujących prac:

g++ -Iinclude test.cpp -o test.exe .\glfw3.dll 

Alternatywą byłoby utworzyć bibliotekę importu z glfw3.dll użyciu MinGW gcc, że masz. Jest to nieco bardziej skomplikowane, ponieważ trzeba utworzyć plik .def, a następnie wywołać dlltool.

Edycja2: Używany przez GCC mingw jest 64-bitowym kompilatorem Windows. Upewnij się, że używasz poprawnej 64-bitowej biblioteki glfw3 i , a nie wersji 32-bitowej. GLFW download section.

+0

To też nie działa, ten sam błąd. – caboose0013

+0

Czy możesz dodać '-v', aby zobaczyć, co jest przekazywane do linkera? Dodaj to do swojego pytania. – greatwolf

+0

@ caboose0013 Tylko w celu wykluczenia oczywistych problemów, czy na pewno 'glfw3.dll, glfw3dll.a, libglfw3.a' jest pod 'C: \ cpp' aka tak potwierdza' dir'? A także uruchamiasz polecenie z 'C: \ cpp' jako bieżący katalog roboczy? – greatwolf

0

Myślę, że masz problem z nazewnictwem. Wygląda na to, że kompilator Mingw32 szuka plików biblioteki glfw3.dll, glfw3.a i glfw3.h. Problem polega na tym, że plik biblioteki ma nazwę libglfw3.a. Teraz musisz zmienić nazwę pliku na glfw3.a, aby mógł go znaleźć. Jeśli to nadal nie działa, musisz zmienić nazwę glfw3dll.a na glfw3.dll.a

+0

nie, to jest całkowicie błędne. mingw działa tak samo jak gcc, ponieważ jest to po prostu port gcc. Oznacza to, że przełącznik '-l' automatycznie przedrostuje wyszukiwanie za pomocą' lib'. Nazwa 'libglfw3.a' jest poprawnie nazwana. – greatwolf