I'm having trouble linking against Intel MKL using Eclipse CDT. The advice from Intel's Link Line Advisor Tool, per my specific requirements, is to use the Link Line:
-Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl
A more readable form of what I need:
--start-group -lmkl_intel_lp64 -lmkl_sequential -lmkl_core --end-group
The problem is the --start-group --end-group syntax is not (AFAIK) an option within Eclipse. The MKL library has a lot of circular dependencies; this syntax is necessary to avoid having to repeatedly link libraries. Without this syntax, I have this terrible list of libs:
-lmkl_core -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lmkl_sequential -lmkl_core -lmkl_sequential -lmkl_core -lmkl_sequential
So the question is how to configure Eclipse CDT to link Intel MKL libraries, using the --start-group syntax to prevent circular references?
I solved my problem searching StackOverflow. This Answer on Eclipse CDT and the --start-group option was almost exactly the solution. A slight modification was required; putting the $(LIBS) variable in the group, not the $(USER_OBS).
So From:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
To This:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} $(OBJS) $(USER_OBJS) -Wl,--start-group $(LIBS) -Wl,--end-group
Results in a working Eclipse build. Command line looks like:
g++ -L"Intel MKL 2019.5.281/linux/lib" -shared -o "myLibrary.so" ./MyObject.o -Wl,--start-group -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -Wl,--end-group