LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   compiling phc - ld doesn't want to see a library that's in front of it (http://www.linuxquestions.org/questions/programming-9/compiling-phc-ld-doesnt-want-to-see-a-library-thats-in-front-of-it-946931/)

eantoranz 05-25-2012 11:06 PM

compiling phc - ld doesn't want to see a library that's in front of it
 
Hi!

I think I'm very close to finishing compiling phc on kubuntu precise (I've spent a good couple of hours fighting with this compilation process).

Now I've hit a brick wall where ld doesn't want to see a so that's (I think) right in front of it.

The command in question and the output error is like this:
Code:

$ LANG=en g++ -Wextra -Wno-unused-parameter -Wno-write-strings -Wno-deprecated -g -O2 -o src/.libs/phc phc.o -Wl,--export-dynamic  /home/antoranz/Downloads/phc/phc-0.3.0.1/libltdl/./.libs/dlopen.a libltdl/.libs/libltdlc.a -lboost_regex ./.libs/libphc.so -L/usr/local/boost/lib -L/usr/local/php/lib -lgccpp -lgc -lphp5 -ldl -Wl,-rpath -Wl,/usr/local/phc/lib
./.libs/libphc.so: undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
./.libs/libphc.so: undefined reference to `boost::re_detail::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
./.libs/libphc.so: undefined reference to `boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const'
./.libs/libphc.so: undefined reference to `boost::re_detail::put_mem_block(void*)'
./.libs/libphc.so: undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > const&)'
./.libs/libphc.so: undefined reference to `boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >::maybe_assign(boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > > const&)'
./.libs/libphc.so: undefined reference to `boost::re_detail::get_mem_block()'
./.libs/libphc.so: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
./.libs/libphc.so: undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
./.libs/libphc.so: undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
./.libs/libphc.so: undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
./.libs/libphc.so: undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const'
./.libs/libphc.so: undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const'
collect2: ld returned 1 exit status

The symbols are in libboost_regex:
Code:

$ nm -gC /usr/local/boost/lib/libboost_regex.so | grep raise_runtime_error
0007f250 T boost::re_detail::raise_runtime_error(std::runtime_error const&)

So, it's a linker problem. I have tried adding this options when calling g++:
-Wl,-rpath -Wl,/usr/local/boost/lib
-Wl,-L -Wl,/usr/local/boost/lib

Also setting LD_LIBRARY_PATH or (logical or) LD_RUN_PATH to /usr/local/boost/lib to no avail. ld refuses to use the libboost_regex library:

Code:

$ ls /usr/local/boost/lib/libboost_regex.so -l
lrwxrwxrwx 1 root root 24 may 25 20:31 /usr/local/boost/lib/libboost_regex.so -> libboost_regex.so.1.46.1

How can I force ld to see it? Thanks in advance.

Sergei Steshenko 05-26-2012 03:55 PM

Try using

-l:libboost_regex.so

instead of '-lboost_regex' which you have; pay attention to ':' and to full file name.

This approach sometimes helps to resolve linking issues - I never digged why.

Sergei Steshenko 05-26-2012 03:59 PM

Also, read about LD_DEBUG, LD_DEBUG_OUTPUT in http://linux.die.net/man/8/ld-linux - I used the environment variable to debug linker failures.

I think you need LD_LIBRARY_PATH to be set.

pan64 05-26-2012 04:05 PM

you need to use -L <path> to define directories where the libraries located, and -l<libname> to use the lib (libname will not contain the word lib at the beginning and .so at the end), so -lboost_regex would be fine). The problem is that the -L should come first before -l.

Sergei Steshenko 05-26-2012 04:10 PM

Quote:

Originally Posted by pan64;4688385... The problem is that the -L should come first [I
before[/I] -l.

I don't think it matters:


Code:

      -Lsearchdir
      --library-path=searchdir
          Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts.  You may use this option any number of times.  The  directo-
          ries are searched in the order in which they are specified on the command line.  Directories specified on the command line are searched before the default directories.
          All -L options apply to all -l options, regardless of the order in which the options appear.


eantoranz 05-27-2012 06:46 PM

I think the problem is in the ./configure script that is not setting things right. Based on all the information you provided I was able to finish the compilation process.

First I tried adding this to the g++ calls:

Code:

-Wl,-L/usr/local/boost/lib -Wl,-lboost_regex
Thas was enough to make it move ahead. But ultimately it can be hacked on the Makefile.

On LIBS add -lboost_regex
On LDFLAGS add -L/usr/local/boost/lib

Or according to your environment. With that I was able to resume "making" and finish the compilation process.

Thank you all for your kind help.


All times are GMT -5. The time now is 10:30 AM.