1

I need to use triangulation library, developed by Jonathan Shewchuk, in my c++ project. Problem is that C file must be compiled into object file which I have done using provided make file and visual studio compiler. This generates triangle.exe and triangle.obj.

Furthermore, in Qt I included header file triangle.h and object as LIBS += path/triangle.obj

Since there is main function in triangle.c I get the following linking errors:

LNK2005 that _main is already defined in main.obj

LNK2019 unresolved external symbol _triangulate reference

I never worked before with object references so if someone could help me with this one.

M_global
  • 207
  • 4
  • 15
  • 1
    From the source code you need to define TRILIBRARY. See `main() or triangulate() Gosh, do everything.` in triangle.c – drescherjm Jul 07 '14 at 17:52
  • I got that later on, but in the end I got LNK1561 -entry point must be defined. It created object file and executable, but got me this error. Do you have any idea why? – M_global Jul 08 '14 at 06:24

1 Answers1

2

first of all, let's explain you very simply the basics.

In C/C++, when you compile, you first generate object files (.o). They consist of function definition in binary form but can't be executed.

After that, you call the linker which links these objects files to generate an executable.

In a program, you can have only one main function, one unique entry point.

When you wrote LIBS += path/triangle.obj, it's not right. A library on windows is a .dll (dynamic) or .a (static) files.

To solve your problem, I see two different solutions:

1- Easiest !

Create a Qt/C++ program which will call your "triangulation executable" when you want. That way you can compile them separately, with different compilers, etc... You can launch an extern program using QProcess class.

2- Less easy :/

Modify sources file you have starting by removing the main functions, configure Qt/make to have the appropriate compilation command lines to make it works. I don't want to explain more because I ardently advise you to choose the first solution ;)

Martin
  • 877
  • 8
  • 20
  • 2
    I think (haven't actually tried) `LIBS += path/triangle.obj` is just fine in the sense, that it adds that *.obj* file to linking. Nothing fundamentally wrong about that, if the "library" really is just single object file (so, generated from single source file). – hyde Jul 07 '14 at 20:19
  • I figured out that I can simply merge several object files in library (.lib). I just merged one I have and it linked properly. Thank you for the ideas. – M_global Jul 08 '14 at 06:16