0

I've been pulling my hair out trying to figure out how to compile my app with boost regex.

I've installed boost from source on centos 5.

g++ -lboost_regex -o my_app my_app.c $(mysql_config --libs --cflags) 

It compiles without any errors, however when I execute it:

error while loading shared libraries: libboost_regex.so.1.46.1: cannot open shared object file: No such file or directory 

The location of that file is:

/usr/local/lib/libboost_regex.so.1.46.1 

Anyone experience the same issues?

1
  • 1
    Given that this is about Boost, why the C tag and the "C/C++" in the question title? Shouldn't this be straight C++? Commented Mar 24, 2011 at 16:43

2 Answers 2

3

Did you try LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH your_program to make sure it knows where to find the shared object? You can set the path when you link by using -Wl,-R/usr/local/lib.

EDIT: To be more clear, when you link your code the linker will embed an RPATH and RUNPATH into the binary. These values tell the runtime loader where to find required shared objects.

If you add -Wl,-R/usr/local/lib to your link command that should cause it to embed that directory and always check it when loading your program.

Sign up to request clarification or add additional context in comments.

4 Comments

that worked! however, is there a way permanately set the LD_LIBRARY_PATH so I don't have to call it before my app's path every time?
sorry to bug you one last time, I'm a newbie with c++. I've added the -R /usr/local/lib to the g++ compile command however it's giving me "g++: unrecognized option '-R'"
@Joe You're right, it's a linker option so you have to pass it through with -Wl,, I fixed my answer.
I don't get something in general. Let me grab this opportunity to ask the question. Why do we need libboost_regex.so for the executable to work after we used -lboost_regex?
0

Try this.

$ LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH
$ export LD_LIBRARY PATH

Now try and tell us what happens.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.