2

我正在尝试构建我的 openGL 项目,在我尝试使用 SOIL 库 (http://www.lonesock.net/soil.html) 从图像加载纹理之前,一切都运行良好。这个库带有一个 SOIL.h 和一个 libSOIL.a 文件。

这就是我做make时得到的:

g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/main.o src/main.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/file_ply_stl.o src/file_ply_stl.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/Proyecto.o src/Proyecto.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/Clock.o src/Clock.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/utils.o src/utils.cpp

...

g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/primitives/cilindro.o src/primitives/cilindro.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g   -c -o src/primitives/cono.o src/primitives/cono.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -o app -L./lib src/main.o src/file_ply_stl.o src/Proyecto.o src/Clock.o src/utils.o src/Window.o src/Light.o src/Material.o src/PlyModel.o src/Placeable.o src/Moveable.o src/Model.o src/Texture.o src/Geometry.o src/TriGeometry.o src/TriIndGeometry.o src/Entity.o src/Camera.o src/Bounded.o src/Animatable.o src/Scene.o src/Graphics.o src/Vert.o src/Path.o src/Ant.o src/Tank.o src/Chess.o src/primitives/tetra.o src/primitives/cubo.o src/primitives/cilindro.o src/primitives/cono.o -lsfml-window -lsfml-system -lX11 -lXext -lXmu -lXi -lXt -lSM -lICE -lGLU -lGL -lglut -lSOIL
src/Texture.o: In function `Texture::ini(char const*)':
/home/roger/t/ig/prac/proyecto/src/Texture.cpp:9: undefined reference to `SOIL_load_OGL_texture'
collect2: ld devolvió el estado de salida 1
make: *** [app] Error 1

这就是我的 Makefile:

TARGET = app

MODULES = src/main.o src/file_ply_stl.o src/Proyecto.o src/Clock.o src/utils.o
ENGINE = src/Window.o src/Light.o src/Material.o src/PlyModel.o src/Placeable.o src/Moveable.o src/Model.o src/Texture.o src/Geometry.o src/TriGeometry.o src/TriIndGeometry.o src/Entity.o src/Camera.o src/Bounded.o src/Animatable.o src/Scene.o src/Graphics.o src/Vert.o
GAME = src/Path.o src/Ant.o src/Tank.o
PRIMITIVES = src/Chess.o src/primitives/tetra.o src/primitives/cubo.o src/primitives/cilindro.o src/primitives/cono.o

CXX = g++
LIBDIR = ./lib
INCDIR = ./src

LIBS = -lsfml-window -lsfml-system -lX11 -lXext -lXmu -lXi -lXt -lSM -lICE -lGLU -lGL -lglut -lSOIL

LDFLAGS = -L$(LIBDIR)
CXXFLAGS = -I$(INCDIR) -Wl,-rpath,$(LIBDIR) -O3 -g

$(TARGET): $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES)
    $(CXX) $(CXXFLAGS) -o $(TARGET) $(LDFLAGS) $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES) $(LIBS)

clean:
    rm -f $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES) $(TARGET)

这就是我的文件层次结构:

.:
lib Makefile src

./lib:
libsfml-audio.so       libsfml-graphics.so.2.0  libsfml-system.so.2    libSOIL.a
libsfml-audio.so.2     libsfml-network.so       libsfml-system.so.2.0  libSOIL.a.1
libsfml-audio.so.2.0   libsfml-network.so.2     libsfml-window.so      libSOIL.a.1.0
libsfml-graphics.so    libsfml-network.so.2.0   libsfml-window.so.2
libsfml-graphics.so.2  libsfml-system.so        libsfml-window.so.2.0

./src:
Animatable.cpp  Clock.cpp         Light.cpp     Moveable.h     random.h         TriGeometry.h
Animatable.h    Clock.h           Light.h       Path.cpp       Scene.cpp        TriIndGeometry.cpp
Ant.cpp         Entity.cpp        main.cpp      Path.h         Scene.h          TriIndGeometry.h
Ant.h           Entity.h          main.h        Placeable.cpp  SFML             utils.cpp
Bounded.cpp     file_ply_stl.cpp  Material.cpp  Placeable.h    SOIL             utils.h
Bounded.h       file_ply_stl.h    Material.h    PlyModel.cpp   Tank.cpp         Vert.cpp
Camera.cpp      Geometry.cpp      matrix.h      PlyModel.h     Tank.h           vertex.h
Camera.h        Geometry.h        Model.cpp     primitives     Texture.cpp      Vert.h
Chess.cpp       Graphics.cpp      Model.h       Proyecto.cpp   Texture.h        Window.cpp
Chess.h         Graphics.h        Moveable.cpp  Proyecto.h     TriGeometry.cpp  Window.h

./src/primitives:
...

./src/SFML:
...

./src/SFML/Audio:
...

./src/SFML/Graphics:
...

./src/SFML/Network:
...

./src/SFML/System:
...

./src/SFML/Window:
...

./src/SOIL:
SOIL.h

我不知道发生了什么,以及为什么编译器找不到库文件。我在 Texture.h 中有 #include "SOIL/SOIL.h",在 Texture.cpp:9 中有对 SOIL_load_OGL_texture 的调用,这是 SOIL.h 中定义的函数名称。¿ 我做错了什么?

编辑

我正在使用提供的库,我自己编译它并且它有效。

4

1 回答 1

0

我必须在编译 SOIL 库时写下这个答案,即使这个问题是 4 年前提出的,因为在我找到 CMakeLists.txt 之前自己编写 CMakeLists.txt 非常困难。

CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project (SOIL)

set (SOIL_BUILD_TESTS false CACHE BOOL "Build tests")

if(ANDROID)
   # Android requires GL ES 2.0 package automatically
  set(LIBRARIES GLESv2)
else()
  find_package (OpenGL REQUIRED)
  include_directories (${OPENGL_INCLUDE_DIR})
  set(LIBRARIES ${OPENGL_LIBRARIES})
endif()

file (GLOB SOIL_SOURCES src/*.c)
file (GLOB SOIL_HEADERS src/*.h)

add_library (SOIL ${SOIL_SOURCES} ${SOIL_HEADERS})
target_link_libraries (SOIL ${LIBRARIES})

install (TARGETS SOIL
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install (FILES ${SOIL_HEADERS} DESTINATION include/SOIL)

if (SOIL_BUILD_TESTS)
    add_executable (test_SOIL src/test_SOIL.cpp)
    target_link_libraries (test_SOIL SOIL)
    install (TARGETS SOIL test_SOIL RUNTIME DESTINATION bin)
endif ()
于 2016-11-05T13:01:26.557 回答