我正在尝试构建自己的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年前问这个问题,我在编译SOIL库时也必须写下这个答案,因为在我找到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 ()

关于c++ - 在G++ Linux上链接静态libSOIL.a的未定义引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10906584/

10-10 10:10