The linker cares about the order of -l options because it satisfies
references to global symbols during a left-to-right scan of the files on
its command line, and in this context a "-l" option actually counts as a
file. So, if you want a library libxyz.{a,so} to satisfy references to
symbol abc, the "-lxyz" linker option should be to the right of the
files that reference abc on the linker command line.Compiler developers: I'm not at expert in the compiler's command line handling, but we probably should be treating "-l" options as if they were files, in terms of how they are ultimately placed in the target C compiler's command line when it's time to link the user program. greg On Thu, 20 Feb 2014, Michael Ferguson wrote:
Hi Tiffany - When compiling with --llvm, the code that generates the link-line is in compiler/util/clangUtil.cpparound line 1488 in makeBinaryLLVM. In particular, I believe your -lfftw3 option is ending up in the libFlag array and thus getting included early on in the compile line; while most of the other options are later. Besides fixing the compiler, one way to work around this behavior is probably to explicitly name the .a file you are trying to link with instead of using the -L/-l flags. I'm not very smart about linker library order. Can you explain what the Chapel compiler should be doing in these cases, and why the linker cares about the order of the -l options? Thanks, -michael On 02/20/2014 01:32 PM, Mintz, Tiffany M. wrote:I am compiling chapel with llvm and I am getting linker ‘undefined reference’ errors. I am linking to a library in a local directory so I provide the library and library path on the chapel command line. During linking, these values are placed at the beginning of the generated command line which is causing the error. Here is the command line I’m using and the generated command line for the linking, respectively: My command line: /data1/projects/prog-guided-reliability/chapel-1.8.0/bin/linux64/chpl -I. -I/home/tmj/fftw-3.3.3/include --print-commands --savec gen_c --llvm bitmap.h fft.h glob_wrapper.h read_glyph.h ssca3.h sys_util.h write_image.h main.chpl createBitmap.o fft.o glob_wrapper.o read_glyph.o sys_util.o write_image.o -o ssca3 -L/home/tmj/fftw-3.3.3/lib -lfftw3 Linker command line: /data1/projects/prog-guided-reliability/chapel-1.8.0/third-party/llvm/install/linux64-gnu/bin/clang++ -pthread -L/home/tmj/fftw-3.3.3/lib -lfftw3 gen_c/chpl__module.bc /data1/projects/prog-guided-reliability/chapel-1.8.0/lib/linux64.gnu.loc-flat.tasks-fifo.pthreads.tmr-generic.mem-default.atomics-intrinsics.gmp.re-none.wide-struct.fs-none/main.o -o gen_c/ssca3.tmp createBitmap.o fft.o glob_wrapper.o read_glyph.o sys_util.o write_image.o -L/data1/projects/prog-guided-reliability/chapel-1.8.0/third-party/gmp/install/linux64-gnu/lib -Wl,-rpath=/data1/projects/prog-guided-reliability/chapel-1.8.0/third-party/gmp/install/linux64-gnu/lib -L/data1/projects/prog-guided-reliability/chapel-1.8.0/lib/linux64.gnu.loc-flat.tasks-fifo.pthreads.tmr-generic.mem-default.atomics-intrinsics.gmp.re-none.wide-struct.fs-none -lchpl -lm -lpthread -lgmp When I execute the generated command manually with the library (-lfftw3) at the end of the command line, there is no error. Is there any way for me to control the position of the linker arguments from the original command line? Thanks, Tiffany ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users
------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users
