problem with linking clhep-libraries with g++
Operating system: CentOS Linux release 7.4.1708 (Core)
Problem description:
I experienced a problem with clhep-config --libs
and clhep-config --include
. I wrote a very simple test example of a c++-code that basically does nothing. When I wanted to compile the code with loading the clhep-libraries (still without using any of its functionality in the code), I got the following error message:
Input: g++ -std=c++11 $(clhep-config --libs) -o test.exe test.cc
Error: /usr/bin/ld: cannot find -lCLHEP-2.4.0.1 collect2: error: ld returned 1 exit status
Finding the solution:
When I look at the output of clhep-config --libs
yielding -L"/localhome/wagner/Tools/clhep/install/lib" -lCLHEP-2.4.0.1
, and insert this instead everything works:
Input: g++ -std=c++11 -L"/localhome/wagner/Tools/clhep/install/lib" -lCLHEP-2.4.0.1 -o test.exe test.cc
When looking at both expressions with echo
, the difference is that the quotation marks (") in the first case are still present, while they are gone in the second version.
Working solution:
Open the clhep-config
file and go to the line
--libs) echo -L\"${libdir}\" -lCLHEP-2.4.0.1
And remove both \"
:
--libs) echo -L${libdir} -lCLHEP-2.4.0.1
Same solution for clhep-config --include
Also remove the quotation marks in line:
--include) echo -I\"${includedir}\"
Working code:
After these changes the following line worked without errors (now also including some CLHEP-classes inside the test-code):
g++ -std=c++11 $(clhep-config --libs) $(clhep-config --include) -o test.exe test.cc