I am using OBJ-Loader to load .obj. For my project, I need to include the OBJ_Loader.h in multiple files. It gives me the LNK2005 linking error on visual studio. It says something like "the object file is already defined". But if I include it twice in a single file, it works okay.
Asked
Active
Viewed 159 times
0
-
Edit the header and add `inline` to the free functions that are missing it. This looks to be an [old issue](https://github.com/Bly7/OBJ-Loader/issues/17) once fixed but now [returned](https://github.com/Bly7/OBJ-Loader/issues/28). – dxiv Mar 03 '21 at 06:37
-
Do you mean every single function that doesn't have it, including the overloaded operators? – Shuvo Sarker Mar 03 '21 at 16:29
-
1Just the [free functions](https://stackoverflow.com/questions/4861914/what-is-the-meaning-of-the-term-free-function-in-c). Member functions defined inside the class are implicitly inline. – dxiv Mar 04 '21 at 00:01
-
It works! But can you please explain what is happening? – Shuvo Sarker Mar 04 '21 at 02:45
-
1From the [LNK2005](https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-160) page: "*This error can occur when a header file defines a function that isn't inline. If you include this header file in more than one source file, you get multiple definitions of the function in the executable. [...] Possible solutions include: Add the inline keyword to the function: [...]*". Some more details under the question I proposed as a [duplicate](https://stackoverflow.com/questions/6964819/function-already-defined-error-in-c). – dxiv Mar 04 '21 at 02:53
-
If this answer solves your problem, I would appreciate it if you could write them as answer and mark them. Because this will be beneficial to other community. – Barrnet Chou Mar 30 '21 at 07:39