Mon, 06/17/2024 - 17:53
I want to load an OBJ model with an MTL material, so I included the necessary headers:
#include <RWObj_Material.hxx>
#include <RWObj_MtlReader.hxx>
But when I declare the variable:
NCollection_DataMap<TCollection_AsciiString, RWObj_Material> aMaterials;
RWObj_MtlReader aMtlReader(aMaterials);
The compiler gives an error:
Error LNK2019 Unresolved external symbol "public: __cdecl RWObj_MtlReader::~RWObj_MtlReader(void)" (??1RWObj_MtlReader@@QEAA@XZ), referenced in the function main. opencascadeLoadObjTest
This is not the only error, but it is enough to illustrate the issue. It seems that the corresponding destructor is not linked, so the compilation fails. I have added a link to TKRWMesh.lib, but it still doesn't work. I suspect that some functions may not be correctly exported in TKRWMesh, but I do not know how to fix it. I am using version 7.7.0, and 7.8.0 has the same issue. I would like to know if there is any method to help me resolve this issue. Thank you.
Mon, 06/17/2024 - 20:24
Hello, you need to link any TK that are used to. This satting should be on your application side. OBJ needs TKService for example. 7.8 OBJ moved from TKRWMesh to TKDEOBJ
Best regards, Dmitrii.
Tue, 06/18/2024 - 06:12
Hello, thank you for your response. I have linked all the libraries that can be linked, and I have tested both versions 7.7 and 7.8, still got the error. Let me demonstrate how to trigger this issue:
C:\occt-vc143-64\inc
. In the Library Directories, addC:\occt-vc143-64\win64\vc14\lib
.TKBinXCAF.lib TKBin.lib TKBinL.lib TKBinTObj.lib TKBO.lib TKBool.lib TKBRep.lib TKCAF.lib TKCDF.lib TKD3DHost.lib TKD3DHostTest.lib TKDCAF.lib TKDE.lib TKDECascade.lib TKDEGLTF.lib TKDEIGES.lib TKDEOBJ.lib TKDEPLY.lib TKDESTEP.lib TKDESTL.lib TKDEVRML.lib TKDFBrowser.lib TKDraw.lib TKernel.lib TKFeat.lib TKFillet.lib TKG2d.lib TKG3d.lib TKGeomAlgo.lib TKGeomBase.lib TKHLR.lib TKIVtk.lib TKIVtkDraw.lib TKLCAF.lib TKMath.lib TKMesh.lib TKMeshVS.lib TKMessageModel.lib TKMessageView.lib TKOffset.lib TKOpenGl.lib TKOpenGles.lib TKOpenGlesTest.lib TKOpenGlTest.lib TKPrim.lib TKQADraw.lib TKRWMesh.lib TKService.lib TKShapeView.lib TKShHealing.lib TKStd.lib TKStdL.lib TKTInspector.lib TKTInspectorAPI.lib TKTObj.lib TKTObjDRAW.lib TKToolsDraw.lib TKTopAlgo.lib TKTopTest.lib TKTreeModel.lib TKV3d.lib TKVCAF.lib TKView.lib TKViewerTest.lib TKVInspector.lib TKXCAF.lib TKXDEDRAW.lib TKXMesh.lib TKXml.lib TKXmlL.lib TKXmlTObj.lib TKXmlXCAF.lib TKXSBase.lib TKXSDRAW.lib TKXSDRAWDE.lib TKXSDRAWGLTF.lib TKXSDRAWIGES.lib TKXSDRAWOBJ.lib TKXSDRAWPLY.lib TKXSDRAWSTEP.lib TKXSDRAWSTL.lib TKXSDRAWVRML.lib
Then create a new
main.cpp
in the project and add the following code:mtlReader
, and I'm not quite clear why this is happening.Tue, 06/18/2024 - 09:20
Classes like
RWObj_MtlReader
have been considered as internal details forRWObj_Reader
andRWObj_CafReader
, hence they lack someStandard_EXPORT
attributes (by mistake or by intention).Any reason for using
RWObj_MtlReader
directly?RWObj_Reader
will read MTL file referred by OBJ file on its own, if it is properly specified.Tue, 06/18/2024 - 07:52
Hi, thank you, I think this is the reason. After reading the official documentation, I mistakenly thought that I needed to manually read and load the MTL file, which is why I called RWObj_MtlReader. So I guess the problem should be solved, and I will directly use RWObj_Reader to read the MTL file.
Tue, 06/18/2024 - 09:49
Hi, how can I specify the MTL when reading the OBJ file? I didn't see how to specify it in the documentation, and I think I may have missed something. Is there any example code for reference?
Tue, 06/18/2024 - 10:50
Take a look into OBJ format description. It should be specified in OBJ file via
mtllib
statement.Tue, 06/18/2024 - 13:22
Thank you! I successfully displayed the OBJ model with materials using the following code: