I am using boost::filesystem in my sample program, but getting linking error.
Here is the sample program:
#include<boost/filesystem.hpp>
using namespace std;
int main()
{
string fromPath = "/home/anurag/testfile";
string toPath = "/home/anurag/testfile";
boost::filesystem::copy_file(fromPath,toPath);
return 0;
}
Here is the steps in an attempt to fix this issue:
1. g++ -g test.cpp -o out -I/apps/rcast/anurag/vendor/RH6.1AS_64/x86_64/boost_1_64_0/
Note: inside this boost
and lib
directories present,and the filesystem.hpp
is in boost/
I got linking errors here because i had missed to include lboost_system
and lboost_filesystem
2. Specified -L option and specified the libraries during build :
g++ -g test.cpp -o out -I/apps/rcast/anurag/vendor/RH6.1AS_64/x86_64/boost_1_64_0/ -L/apps/rcast/anurag/vendor/RH6.1AS_64/x86_64/boost_1_64_0/lib/ -lboost_system -lboost_filesystem
Error:
/usr/bin/ld: cannot find -lboost_filesystem
/usr/bin/ld: cannot find -lboost_system
collect2: error: ld returned 1 exit status
3. added library path in LD_LIBRARY_PATH even though not required as i specified in -L option
Now echo $LD_LIBRARY_PATH
shows /xenv/gcc_gnu/X/6.1.0/lib64:/apps/rcast/anurag/vecndor/RH6.1AS_64/x86_64/boost_1_64_0/lib
Still same Error.
In boost_1_64_0/lib/
libs present are ls -lart libboost*system*
:
libboost_filesystem-gcc61-mt-sd-1_64.a
libboost_system-gcc61-mt-sd-1_64.a
libboost_filesystem-gcc61-mt-s-1_64.a
libboost_system-gcc61-mt-s-1_64.a
-lboost_filesystem
causes the linker to look for a file named libboost_filesystem.a
or libboost_filesystem.so
as your file is called libboost_filesystem-gcc61-mt-s-1_64.a
you need to pass -lboost_filesystem-gcc61-mt-s-1_64
to the linker