Re: [Boost-users] How do you compile Boost C++ code in Ubuntu?
Greetings,
I realized that when I installed certain packages from the Ubuntu
Software Center, I had broken some dependencies. That may have caused
the problem. Now, I have reinstalled Boost C++.
See the following for a snippet from the Terminal session that
indicates the availability of the previously missing files.
Go Bears >ls -al | grep libboost_system
-rw-r--r-- 1 root root 48666 Jan 2 2012 libboost_system.a
lrwxrwxrwx 1 root root 17 Jan 2 2012
libboost_system-mt.a -> libboost_system.a
lrwxrwxrwx 1 root root 25 Jan 2 2012
libboost_system-mt.so -> libboost_system.so.1.46.1
lrwxrwxrwx 1 root root 25 Jan 2 2012 libboost_system.so
-> libboost_system.so.1.46.1
-rw-r--r-- 1 root root 14568 Jan 2 2012 libboost_system.so.1.46.1
Go Bears >
Go Bears >make all
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
Go Bears >
So, I am back to square one with the "undefined reference" compilation error.
Can you please kindly suggest how can I resolve this problem? Thank you.
Regards
On Thu, Feb 7, 2013 at 8:33 AM, Mateusz Loskot
On 7 February 2013 15:21, Giovanni
wrote: I had set the shell variable $LD_LIBRARY_PATH to: /usr/lib/libboost_system.so. It was originally empty. I used the "echo" command to reflect the path that I had set it to.
I tried to make a point not about how you did set the variable, but about the fact it has incorrect value. Let me copy it once again:
"LD_LIBRARY_PATH, which is a colon-separated list of directories" [1]
[1] http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
And you may learn from that what the LD_LIBRARY_PATH is meant to be.
I had installed it with Ubuntu Software Center. Here is a snippet of: /usr/lib [...] -rw-r--r-- 1 root root 14568 Jan 2 2012 libboost_system.so.1.46.1 -rw-r--r-- 1 root root 14568 Jan 5 2012 libboost_system.so.1.48.0
You seem to be missing libboost_system.so library or symlink named libboost_system.so with one of the two as a target. It may look the installation is broken.
When I followed your instructions to install it (again), I couldn't. Here is the transcript from the Terminal. Go Bears >sudo apt-get install libboost-system-dev [sudo] password for arvind: Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
The following packages have unmet dependencies: libboost-system-dev : Depends: libboost-system1.46-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages.
Clearly, something is broken with installation of boost packages in your system. You should seek for help from Ubuntu folks, it's unrelated to Boost.
On 7 February 2013 17:08, Giovanni
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 Best regards, -- Mateusz Loskot, http://mateusz.loskot.net
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
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
It is a quirk of GCC that the libraries used by a source file must appear *after* the source file. Nothing to do with Boost really... John.
On 8 February 2013 16:03, Giovanni
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.
No idea what's wrong really and have no time to investigate it.
But, I've done quick test on Ubuntu 10.04 using Boost 1.40
installed from its packages and small sample from this book
http://en.highscore.de/cpp/boost/errorhandling.html
and it worked for me:
Here is my console log:
mloskot@vb-ubuntu104-x64:~/tmp$ /usr/bin/lsb_release -d
Description: Ubuntu 10.04.4 LTS
mloskot@vb-ubuntu104-x64:~/tmp$ cat bsystem.cpp
#include
participants (3)
-
Giovanni
-
John Maddock
-
Mateusz Loskot