在g ++ linux上链接静态libSOIL.a的未定义引用

时间:2012-06-05 23:56:15

标签: c++ linux g++ static-libraries soil

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

这就是我在做的时候得到的:

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中定义的函数名称。 ¿我做得不好?

修改

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

1 个答案:

答案 0 :(得分: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 ()