2016-05-19 3 views
0

(Hallo, das ist mein erster Beitrag, und ich verwende Dev C++ IDE 5.11)
Ich habe die Header, SOIL.h und den Linker: -lSOIL.
Dieses Programm kompiliert mit keinem Problem und läuft korrekt, aber wenn ich jede Funktion in meinem Code aus der SOIL-Bibliothek hinzufügen, erhalte ich einen Linker-Fehler.
Rezept für Ziel‚Projekt1.exe‘failed
Hier ist der Code von SOIL, die den Linker-Fehler verursacht:
Problem mit SOIL-Bibliothek Linker-Fehler mit C++

unsigned char* image = SOIL_load_image("container.jpg", &width, &height, 0, SOIL_LOAD_RGB); 

(Es gibt wahrscheinlich eine einfache Erklärung und für diese Antwort, aber ich habe überall gesucht, wie ich es nicht finden kann)
. Hinweis: ich verfolge ein Tutorial von der Website learnopengl
Hier ist mein makefile.win:

# Project: Project1 
# Makefile created by Dev-C++ 5.11 
CPP  = g++.exe 
CC  = gcc.exe 
WINDRES = windres.exe 
OBJ  = Untitled2.o 
LINKOBJ = Untitled2.o 
LIBS  = -L"D:/Dev-Cpp/MinGW32/lib" -L"D:/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lopengl32 -lopengl32 -lmingw32 -lSOIL 
INCS  = -I"D:/Dev-Cpp/MinGW32/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include" 
CXXINCS = -I"D:/Dev-Cpp/MinGW32/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include/c++" 
BIN  = Project1.exe 
CXXFLAGS = $(CXXINCS) 
CFLAGS = $(INCS) 
RM  = rm.exe -f 
.PHONY: all all-before all-after clean clean-custom 
all: all-before $(BIN) all-after 
clean: clean-custom 
    ${RM} $(OBJ) $(BIN) 
$(BIN): $(OBJ) 
    $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS) 
Untitled2.o: Untitled2.cpp 
    $(CPP) -c Untitled2.cpp -o Untitled2.o $(CXXFLAGS) 

Compilation log:

Compiling project changes... 
-------- 
- Project Filename: D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Project1.dev 
- Compiler Name: MinGW GCC 4.7.2 32-bit Release 

Building makefile... 
-------- 
- Filename: D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win 

Processing makefile... 
-------- 
- Makefile Processor: D:\Dev-Cpp\MinGW32\bin\mingw32-make.exe 
- Command: mingw32-make.exe -f "D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win" all 

g++.exe Untitled2.o -o Project1.exe -L"D:/Dev-Cpp/MinGW32/lib" -L"D:/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lopengl32 -lmingw32 -Bstatic -lSOIL 

D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x3e): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x72): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xbe): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xf2): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x115): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x15e): more undefined references to `[email protected]' follow 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1d1): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x5e2): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x66a): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x84f): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xdf8): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x100d): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1427): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x15a8): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x161a): undefined reference to `[email protected]' 
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x188c): undefined reference to `[email protected]' 
d:/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o): bad reloc address 0x0 in section `.data' 
d:/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation 
collect2.exe: error: ld returned 1 exit status 

D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win:25: recipe for target 'Project1.exe' failed 
mingw32-make.exe: *** [Project1.exe] Error 1 


Compilation results... 
-------- 
- Errors: 1 
- Warnings: 0 
- Compilation Time: 0.25s 
+0

'Rezept für Ziel' Project1.exe 'fehlgeschlagen' ist nicht sehr informativ, könnten Sie einen früheren Fehler posten? Überprüfen Sie außerdem, ob sich libSOIL in einem der Verzeichnisse/lib in der Zeile LIBS = befindet. – patstew

+0

Der einzige andere Fehler, den ich bekomme, ist: ID zurückgegeben 1 Exit-Status. Und leider gibt es keine früheren Fehler. Ist es die libsoil.a, die im Verzeichnis/lib sein sollte? Das ist jetzt da drin. – newbcoder

+0

Probieren Sie "-lsoil" anstelle von "-SOIL". Auch .a ist eine statische Bibliothek, versuchen Sie '-Wl, -Bstatic' vor' -lsoil' hinzuzufügen. – patstew

Antwort

0

Vielen Dank Patrick Stewart für mich helfen herauszufinden.
Seltsamerweise, wenn ich nicht die -Bstatic hatte, gab es den einzigen Fehler. Als ich dem, was du über das Kompilierungsprotokoll gesagt hast, gefolgt war, gab es mehr Fehler, von denen ich nicht wusste, dass sie da waren. Ich googelte es und fand eine Antwort von dieser Seite:
http://www.gamedev.net/topic/614336-soil-linker-errors/
dass die -lSOIL vor dem -lopengl32 sein musste. Das ist meiner Meinung nach seltsam, aber es ist eine Lösung.