1

I am trying to compile TetGen and use the code below to tetrahedralize a .ply file although I am getting these two linker errors:

LNK2005 main already defined in tetgen.obj

LNK1169 one or more multiply defined symbols found

The files that are includes in my project solution are "tetgen.h", "predicates.cxx", and "tetgen.cxx", and the folder path that these three files are in is included in my Project Properties > C/C++ > General > Additional Include Directories. I did the same for the "monkey.ply" file as well.

This is all the code in my main file:

#include "tetgen.h"

int main()
{
    tetgenio in, out;
    in.firstnumber = 0;
    in.load_ply((char *)"monkey.ply");
    tetgenbehavior* b = new tetgenbehavior();
    tetrahedralize(b, &in, &out);
}

Here are the "tetgen.h", "predicates.cxx", and "tetgen.cxx" files I'm using : https://minhaskamal.github.io/DownGit/#/home?url=https://github.com/libigl/tetgen

I researched these errors and looked around a great amount but can't see why this is occurring. Any help would be greatly appreciated.

2 Answers2

1

LNK2005 main already defined in tetgen.obj

This message tries to tell you that your tetgen library contains the main function. Your "main file" also contains a main function. This is a conflict. You should remove your main function from your code, and read the documentation of the tetgen library on how to provide a replacement. Typically, libraries which define their own main functions require you to rename your main to have some other name, which the documentation should clearly specify.

#include "tetgen.h"

int main_replacement_called_by_tetgen()
{
    ...
}
anatolyg
  • 26,506
  • 9
  • 60
  • 134
0

For anyone who may have this issue in the future with TetGen: The problem was that the TETGEN_LIBRARY flag needed to be defined in tetgen.h. I knew this, but every time I defined the flag, it would cause memory errors without fail. So, I kept TETGEN_LIBRARY undefined to avoid the memory error. Turns out, with TETGEN_LIBRARY defined, it will work. The problem was that "monkey.ply" did not exist/was in the wrong folder. Because "monkey.ply" did not exist it threw an unhandled exception. Why TetGen does not have a simple handle to check if a file exists before it tries to load it or not is beyond me. But that fixed things.