-4

I am compiling code that uses the external library https://www.cs.cmu.edu/afs/cs/project/quake/public/www/triangle.html. All the triangle source and object files are in ~/triangle/ folder. So I compile like this:

g++ -g sobel_aot_run.cpp sobel_x_out.a sobel_y_out.a support.a -ljpeg -lpng -std=c++11 -I ../include -I ../tools -I ~/triangle -lpthread -ldl -o sobel

Even though I have specified -I ~/triangle, running this command gives the following error:

/tmp/cc9AUEre.o: In function `main':
/home/zendevil/Halide/tutorial/sobel_aot_run.cpp:74: undefined reference to `triangulate(char*, triangulateio*, triangulateio*, triangulateio*)'
collect2: error: ld returned 1 exit status

How to compile this?

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
zengod
  • 1,114
  • 13
  • 26
  • 3
    You say that the `triangle` code is still in source form. Did you compile it? If so, which `-l` argument is it supposed to in? – Max Langhof Aug 13 '19 at 11:38
  • 1
    The `-l` option for the Unix/GNU-related linkers I am familiar with is for specifying a particular library file to use. `-lxyz` says to look for a file named `libxyz.a` or `libxyz.dylib` or possibly other suffixes for libraries, and `-lxyz.o` says to look for a file named `xyz.o`. `-l ~/triangle` does not tell the linker to use all object or library files in the directory `~/triangle/`. There is another option with a capital L, `-Ldirectory`, that tells the linker to include `directory` in the places it looks when it is looking for a library. But again, it does not tell the linker to use all… – Eric Postpischil Aug 13 '19 at 11:45
  • … files in that directory. You still have to specify them individually. You can also list object and library files explicitly on the linker command line, without using `-l` or `-L`. For example, `~/triangle/*.o` might do what you need. – Eric Postpischil Aug 13 '19 at 11:46
  • `-I` specifies a directory to look for headers in. – molbdnilo Aug 13 '19 at 11:46
  • 1
    @EricPostpischil He's using `-I`, it just looked like `-l`. – S.S. Anne Aug 13 '19 at 11:46
  • @MaxLanghof I have compiled it using make. – zengod Aug 14 '19 at 11:19
  • @john triangle readme says that TRILIBRARY is set automatically with make. – zengod Aug 14 '19 at 11:20
  • @EricPostpischil doing the *.o trick gives the same error in addition to a warning that path/to/triangle.o is not a directory. – zengod Aug 14 '19 at 11:20
  • I haven't used any -l flags for triangle in this command. All the -l flags in the command are for other things. – zengod Aug 14 '19 at 11:20
  • You need to link with the triangle library (that you built with make), just like you linked with libjpeg and libpng. – Max Langhof Aug 14 '19 at 11:24
  • If you got a warning that `path/to/triangle.o` is not a directory, then you used it after a switch like `-L` or `-I` that expects a directory. To link an object file in with the program, just list it on the command line by itself, not after a switch that expects an argument to go with it. – Eric Postpischil Aug 14 '19 at 11:37
  • @zengod Don't use `-I ~/triangle/*.o` or `-l ~/triangle/*.o`, just use `~/triangle/*.o`. – S.S. Anne Aug 14 '19 at 11:45

1 Answers1

2

-I only specifies to the compiler that you are searching in a directory for files to satisfy #include statements.

You now need to compile and link to the triangulate code that you are using.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76