gpt4 book ai didi

c++ - 在 g++ linux 上链接静态 libSOIL.a 的 undefined reference

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:11:36 24 4
gpt4 key购买 nike

我正在尝试构建我的 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 中定义的函数名称。 ¿我做错了什么?

编辑

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

最佳答案

我在编译 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 ()

关于c++ - 在 g++ linux 上链接静态 libSOIL.a 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10906584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com