简体   繁体   English

在G ++ Linux上链接静态libSOIL.a的未定义参考

[英]Undefined reference linking static libSOIL.a on g++ linux

I'm trying to build my openGL project, all worked well until I tried to use the SOIL library (http://www.lonesock.net/soil.html) for loading textures from images. 我正在尝试构建自己的openGL项目,在我尝试使用SOIL库(http://www.lonesock.net/soil.html)从图像加载纹理之前,所有项目都运行良好。 This library comes with a SOIL.h and a libSOIL.a files. 该库带有SOIL.h和libSOIL.a文件。

That's what I get when doing make: 那就是我在做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

And that's my Makefile: 那就是我的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)

And that's my file hierachy: 这就是我的文件层次结构:

.:
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

I don't know what's going on, and why the compiler doesn't find the library file. 我不知道发生了什么,为什么编译器找不到库文件。 I've got #include "SOIL/SOIL.h" in Texture.h and the call to SOIL_load_OGL_texture in Texture.cpp:9, that's the name on the function as defined in SOIL.h. 我在Texture.h中具有#include“ SOIL / SOIL.h”,在Texture.cpp:9中具有对SOIL_load_OGL_texture的调用,这就是在SOIL.h中定义的函数名称。 ¿What I am doing bad? ¿我在做什么不好?

EDIT 编辑

I was using the library provided, I compiled it myself and it worked. 我使用的是提供的库,我自己对其进行了编译,并且可以正常工作。

I must write down this answer when I compile the SOIL library even the question is asked 4 year ago, because it is so hard to write the CMakeLists.txt myself before I find the CMakeLists.txt. 甚至在4年前问这个问题时,我在编译SOIL库时都必须写下这个答案,因为在我找到CMakeLists.txt之前,自己写CMakeLists.txt非常困难。

the 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 ()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM