I'm using a C++ header library to load stl files to later render them in a VR sample script. Basically, I use the parse_stl library that I found GitHub. The library is included in my main include
file. This file handles several structures like: TriangleSet
(this one generates the triangle models, with their coordinates and colors) and Scene
(which uses TriangleSet
and handles the rendering).
I need to call the function loadSTLModel
from a void function in the Scene
structure. The loadSTLModel
is a void
in TriangleSet
, which later calls stl::parse_stl
. This function takes the filename as a std::string
(apparently), but it is giving me linking errors that I can't understand.
The library works fine I've tested it before, and I've managed to use it in a similar sample but that was more complex and I haven't been able to pass the argument properly in this example. It's clear to me that the error is due to how I pass the filepath variable to the different functions, but I don't know how to fix it.
Here's the error code:
main.obj : error LNK2019: unresolved external symbol "struct stl::stl_data __cdecl stl::parse_stl(class std::basic_string,class std::allocator > const &)" (?parse_stl@stl@@YA?AUstl_data@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall TriangleSet::loadSTLModel(char const *,unsigned int,struct DirectX::XMFLOAT3,struct DirectX::XMFLOAT3)" (?loadSTLModel@TriangleSet@@QAEXPBDIUXMFLOAT3@DirectX@@1@Z)
main.h
struct TriangleSet{
...
void loadSTLModel(const char* filename, uint32_t color, XMFLOAT3 origin, XMFLOAT3 size) {
XMFLOAT3 s = multXMFLOAT(size, XMFLOAT3(0.5,0.5,0.5));
XMFLOAT3 o = origin;
std::string stl_filename = filename;
auto stlData = stl::parse_stl(stl_filename);
...
}
...
}
struct Scene{
...
void Init(){
...
TriangleSet furniture;
std::string FilePathName = "C:/sampleSTL.stl";
XMFLOAT3 Origen = { 0.0f, 0.0f, 0.0f };
XMFLOAT3 Escala = { 1.0f, 1.0f, 1.0f};
furniture.loadSTLModel(FilePathName.c_str(),0xff383838, Origen, Escala);
...
}
parse_stl.h
namespace stl {
struct stl_data {
std::string name;
std::vector<triangle> triangles;
stl_data(std::string namep) : name(namep) {}
};
stl_data parse_stl(const std::string& stl_path);
}
parse_stl.cpp
namespace stl {
...
stl_data parse_stl(const std::string& stl_path) {
std::ifstream stl_file(stl_path.c_str(), std::ios::in | std::ios::binary);
if (!stl_file) {
std::cout << "ERROR: COULD NOT READ FILE" << std::endl;
assert(false);
}
char header_info[80] = "";
char n_triangles[4];
stl_file.read(header_info, 80);
...
...
return info;
}
}