C 链接器错误尝试包含Tiny OBJ加载程序标头文件
C++ Linker error when trying to include tiny obj loader header file
我正在尝试使用tiny_obj_loader将.obj
加载到我的程序中。我有以下使用此库的代码:
void LoadModel(vector<Shape *> &scene, const char *path) {
attrib_t attrib;
vector<shape_t> shapes;
vector<material_t> materials;
std::string error;
bool ret = tinyobj::LoadObj(
&attrib,
&shapes,
&materials,
&error,
path
);
... // Do stuff with the returned data
但是,这给了我以下链接器错误:
Build/skeleton.o: In function `LoadModel(std::vector<Shape*,
std::allocator<Shape*> >&, char const*)':
skeleton.cpp:(.text+0x3025): undefined reference to `tinyobj::LoadObj(tinyobj::attrib_t*, std::vector<tinyobj::shape_t, std::allocator<tinyobj::shape_t> >*, std::vector<tinyobj::material_t, std::allocator<tinyobj::material_t> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, char const*, char const*, bool)'
Makefile:43: recipe for target 'Build' failed
make: *** [Build] Error 1
函数定义是:
bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
std::vector<material_t> *materials, std::string *err,
const char *filename, const char *mtl_basedir = NULL,
bool triangulate = true);
看起来参数类型对我来说是正确的。
我已在
中将.h
文件包含在skeleton.cpp
中 #include "tiny_obj_loader.h"
tiny_obj_loader.h
是文件的名称,该文件位于 skeleton.cpp
的同一目录中。
编辑使用的makefile是:
FILE=skeleton
########
# Directories
S_DIR=Source
B_DIR=Build
########
# Output
EXEC=$(B_DIR)/$(FILE)
# default build settings
CC_OPTS=-std=c++11 -c -pipe -Wall -Wno-switch -O3 -xHOST -qopenmp
LN_OPTS=-qopenmp
CC=icpc
########
# SDL options
SDL_CFLAGS := $(shell sdl2-config --cflags)
GLM_CFLAGS := -I../glm/
SDL_LDFLAGS := $(shell sdl2-config --libs)
########
# This is the default action
all:Build
########
# Object list
#
OBJ = $(B_DIR)/$(FILE).o
########
# Objects
$(B_DIR)/$(FILE).o : $(S_DIR)/$(FILE).cpp $(S_DIR)/SDLauxiliary.h $(S_DIR)/TestModelH.h $(S_DIR)/tiny_obj_loader.h
$(CC) $(CC_OPTS) -o $(B_DIR)/$(FILE).o $(S_DIR)/$(FILE).cpp $(SDL_CFLAGS) $(GLM_CFLAGS)
########
# Main build rule
Build : $(OBJ) Makefile
mkdir -p $(B_DIR) && $(CC) $(LN_OPTS) -o $(EXEC) $(OBJ) $(SDL_LDFLAGS)
clean:
rm -f $(B_DIR)/*
在实际包含tiny_obj_loader.h
之前,请确保 #define TINYOBJLOADER_IMPLEMENTATION
。否则,预处理器将已经在该文件上运行,并且您将无法获得实现。
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- 如何使用Qt 3D库加载和显示搅拌机.obj源文件场景
- 加载的 obj 模型闪烁并崩溃应用程序
- C 链接器错误尝试包含Tiny OBJ加载程序标头文件
- 在C/C (JIT)中,在运行时加载并链接OBJ文件
- 尝试加载DirectX 11中的obj文件时,向量下标
- DirectX11 如何加载 Obj 文件
- 带有c/cpp材料文件的Wavefront obj加载程序
- 虚幻引擎4:加载OBJ文件
- 具有不同索引的 Obj 文件加载器
- 加载 .obj 文件时出现链接器错误
- 正在openGL中加载obj文件
- 在opengl中加载obj文件时,矢量下标超出范围
- 在Opengl中为加载的OBJ模型制作着色器
- 从obj文件加载纹理
- OpenGL加载OBJ模型,纹理失真
- 二进制文件 - obj(game) 保存并加载 obj
- 从obj文件加载时显示单色而不是纹理
- 在DirectX9中使用ASSIMP加载.obj模型