Resolving "undefined reference" compilation errors of Boost C++ code in Ubuntu -
Resolving "undefined reference" compilation errors of Boost C++ code in Ubuntu -
this question has reply here:
undefined reference boost::system::system_category() when compiling 6 answersfrom terminal session:
go trojans >make g++ -static -i/usr/include/boost -i/usr/include/boost/filesystem get_sys_info.cpp /tmp/cc6nk9ev.o: in function `__static_initialization_and_destruction_0(int, int)': get_sys_info.cpp:(.text+0x13a): undefined reference `boost::system::generic_category()' get_sys_info.cpp:(.text+0x146): undefined reference `boost::system::generic_category()' get_sys_info.cpp:(.text+0x152): undefined reference `boost::system::system_category()' collect2: ld returned 1 exit status make: *** [all] error 1 go trojans >
the c++ code importing boost c++ filesystem library:
#include <iostream> #include <string> #include <stdio.h> #include <stdlib.h> // include boost c++ libraries #include <boost/filesystem.hpp> using namespace boost::filesystem; using namespace std; int main() { string my_str = "this string."; cout << my_str << endl; /* my_str = system("pwd"); my_str.append("\b\b\b\b\b\b\b\b extra"); cout << my_str << "a\b\b\b\b\b\b=" << endl; */ path p("."); cout << p << "==" << endl; homecoming 0; }
snippets terminal session @ directory boost c++ libraries located.
go trojans >pwd /usr/include/boost go trojans >ls -al total 1308 drwxr-xr-x 86 root root 12288 jan 29 09:30 . drwxr-xr-x 119 root root 20480 feb 4 08:08 .. ... drwxr-xr-x 5 root root 4096 jan 29 09:30 filesystem -rw-r--r-- 1 root root 1340 jan 5 2012 filesystem.hpp
how resolve undefined references? importing boost c++ filesystem library correctly? compiling code correctly?
what mistakes? can please kindly help me?
thank much, , have awesome day! ciao!
you need utilize -l/path/to/your/library
in front end of phone call -lboost_system
tell compiler find shared object. however, if can compile code, not run because runtime cannot locate file anyway, you're forced update path.
i'm assuming you're on school computer editing ld_library_path
or utilizing /sbin/ldconfig
illegal.
if they're not illegal, can either
export ld_library_path=$ld_library_path:/path/to/boost
in ~/.bashrc
or equivalent
or can
touch /etc/ld.so.conf.d/boost.conf
vi /etc/ld.so.conf/boost.conf
put path boost library in here , save file. run:
/sbin/ldconfig
which reparses in /etc/ld.so.conf.d
, update runtime paths.
good luck!
c++ ubuntu boost ubuntu-12.04
Comments
Post a Comment