Greetings All,
Thank you so much, Mr. Loskot, for spending your precious time to
help a C++ dingbat like me.
I followed your instructions to link the libraries, with the
"-lboost_filesystem -lboost_system" sequence of linking the
aforementioned Boost C++ libraries.
However, I cannot resolve the linking error. I have included a
snippet from my Terminal session below.
Go Bears >make all
g++ -L/usr/lib -lboost_filesystem -lboost_system get_sys_info.cpp
/tmp/cchfM9Y3.o: In function
`__static_initialization_and_destruction_0(int, int)':
get_sys_info.cpp:(.text+0x13f): undefined reference to
`boost::system::generic_category()'
get_sys_info.cpp:(.text+0x14b): undefined reference to
`boost::system::generic_category()'
get_sys_info.cpp:(.text+0x157): undefined reference to
`boost::system::system_category()'
/tmp/cchfM9Y3.o: In function `boost::filesystem3::path::codecvt()':
get_sys_info.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x5):
undefined reference to
`boost::filesystem3::path::wchar_t_codecvt_facet()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Go Bears >make linkerr
g++ -t -Wl,--start-group -L/usr/lib -lboost_filesystem -lboost_system
get_sys_info.cpp -Wl,--end-group
/usr/bin/ld: mode elf_x86_64
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o
-lboost_filesystem (/usr/lib/libboost_filesystem.so)
-lboost_system (/usr/lib/libboost_system.so)
/tmp/ccKXKAXo.o
-lstdc++ (/usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so)
-lm (/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libm.so)
-lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so)
/lib/x86_64-linux-gnu/libc.so.6
(/usr/lib/x86_64-linux-gnu/libc_nonshared.a)elf-init.oS
/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
-lgcc_s (/usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so)
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
/tmp/ccKXKAXo.o: In function
`__static_initialization_and_destruction_0(int, int)':
get_sys_info.cpp:(.text+0x13f): undefined reference to
`boost::system::generic_category()'
get_sys_info.cpp:(.text+0x14b): undefined reference to
`boost::system::generic_category()'
get_sys_info.cpp:(.text+0x157): undefined reference to
`boost::system::system_category()'
/tmp/ccKXKAXo.o: In function `boost::filesystem3::path::codecvt()':
get_sys_info.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x5):
undefined reference to
`boost::filesystem3::path::wchar_t_codecvt_facet()'
/usr/bin/ld: link errors found, deleting executable `a.out'
collect2: ld returned 1 exit status
make: *** [linkerr] Error 1
Go Bears >
The Make targets from my Makefile are:
all:
g++ -L/usr/lib -lboost_filesystem -lboost_system get_sys_info.cpp
./a.out
linkerr:
g++ -t -Wl,--start-group -L/usr/lib -lboost_filesystem -lboost_system
get_sys_info.cpp -Wl,--end-group
./a.out
I had a look at the blog, and used the "-t", "-Wl,--start-group",
and "-Wl,--end-group" options to help me "figure" out what is going
on.
Did I fail to include an appropriate header file in my C++ code, or
did I fail to include another Boost C++ Library?
How can I tell what is wrong, where did I go wrong, and figure out
how can I resolve this? Can you please kindly share your wisdom and
insights with me? Thank you very much, and have an awesome day!
Regards
On Thu, Feb 7, 2013 at 9:53 AM, Mateusz Loskot
On 7 February 2013 17:08, Giovanni
wrote: g++ -L/usr/lib -lboost_system get_sys_info.cpp /tmp/cckONUUl.o: In function `__static_initialization_and_destruction_0(int, int)': get_sys_info.cpp:(.text+0x13f): undefined reference to `boost::system::generic_category()' get_sys_info.cpp:(.text+0x14b): undefined reference to `boost::system::generic_category()' get_sys_info.cpp:(.text+0x157): undefined reference to `boost::system::system_category()' /tmp/cckONUUl.o: In function `boost::filesystem3::path::codecvt()': get_sys_info.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x5): undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()' collect2: ld returned 1 exit status make: *** [all] Error 1
-lboost_filesystem -lboost_system
So, I am back to square one with the "undefined reference" compilation error.
Linking error, you mean.
Can you please kindly suggest how can I resolve this problem? Thank you.
Volodya's blog post may help too
http://vladimir_prus.blogspot.co.uk/2009/06/linking-101.html