1

I am attempting to write a cgi program (using cgicc) which incorporates the boost regex library. The program works perfectly with std regex, but I am trying to change to boost regex to test the performance difference.

The program also works perfectly if I create an offline version that does not use cgicc or run through a browser. When I compile this program I use the following command lines:

c++ -std=c++11 resourcelocator.cpp -I /path/include -I /path/boost_1_57_0 -L /path/src -L/path/lib -lcgicc -lgmp -lcurl -lcurlcpp -lboost_regex -o resourcelocator.cgi

The executable which results always looks in the wrong place for the boost regex library so I have to do the following as well:

install_name_tool -change libboost_regex.dylib /path/libboost_regex.dylib resourcelocator.cgi

After that, the offline version works perfectly. However, if I attempt to write an almost identical program as a cgi script and run it from a browser, I get a 500 error every time. I tried reducing the script to doing nothing but printing out the header and it still returned a 500 error. If I do not link -lboost_regex when I compile the program will work again (as long as I take out the boost regexes, of course).

I get a few error messages when it runs - in essence: "dyld: Library not loaded:" then "Reason: no suitable image" then \\t/path/libboost_regex.dylib: stat() failed with errno=13, referer: http://localhost/test.html

Why would linking the library cause the cgi to fail? Is there any way for me to use this library in a cgi program?

Jonathan Basile
  • 649
  • 1
  • 10
  • 20
  • 1
    Its possible to just include the regex src code into your application then whatever your settings are it compiles accordingly. I think the 16 cpp files are somewhere in `..\libs\regex\src`. This is the way I do it, adds about 300k overhead, but works without problem. Its not as fancy as jumping through hoops, but what the heck.. –  May 26 '15 at 21:34
  • This sounds promising. What do I do about internals.hpp (the one hpp file in the library)? After pasting in the code I get `'internals.hpp' file not found #include "internals.hpp"` – Jonathan Basile May 26 '15 at 21:45
  • 1
    I assume you mean `c_regex_traits.cpp or wc_regex_traits.cpp`. All the includes the regex source needs are in the distribution directory. Just include the distribution path in the global include directories. For example, ``\libs\regex\src is where the cpp files are so add include path `` and it will find what it needs. And there probably isin't a need to specify `internals.hpp` with your source code, unless you need it. –  May 26 '15 at 21:54
  • 1
    FWIW you should have the 1_57 full Boost distribution (@500 MB's) unpacked and on your hardrive somwehre in a semi-permanent location (for compiling). The regex source only uses what it needs from the distribution. Its really a small footprint when your app compiles. –  May 26 '15 at 22:03
  • 1
    If you have (and you probably will) more questions as you do this, just let me know and I'll give you my general settings. I actually use it with/without the ICU library. Talk about big dll's (ICU). –  May 26 '15 at 22:06
  • 1
    All the include (hpp) files are located under the `boost` subdirectory. Any #includes within your source should be prefixed with <`boost`/...hpp>. You must set the global project include to be –  May 26 '15 at 22:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78846/discussion-between-jonathan-basile-and-sln). – Jonathan Basile May 26 '15 at 22:28

1 Answers1

1

You linked it - dynamically.

This means that, at runtime, the dynamic linker will have to find the dynamic library to satisfy the symbols (a dll, so or dylib).

Your system's runtime linker is failing to locate the binary.

I'm not a Mac user, but on linux you'd set LD_LIBRARY_PATH (I think I remember seeing this on OSX too). Some UNIX-en spell that LIB_PATH.

You can often also "bake" the hint-path right into the main program with -Wl,rpath (see e.g. boost libraries built with relative paths)

I think the install_name_tool is supposed to serve the same purpose. Perhaps it runs in a different environment/under a different user which makes it stop working.

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • The only way I managed to get the library to link statically was to remove libboost_regex.dylib from the folder so that only libboost_regex.a remained. Just in case any OS X users come across this in the future. – Jonathan Basile May 27 '15 at 16:02
  • @JonathanBasile Thanks for the update. The conclusion is quite surprising because you never mentioned static linking. In fact, you were very actively requiring the dynamic link (`-lboost_regex` and `.dylib` are indicators). Otherwise, the linker input should just read `libboost_regex.a` (without -l) – sehe May 27 '15 at 16:09
  • When I try that I get `no such file or directory: 'libboost_regex.a'` – Jonathan Basile May 27 '15 at 17:02
  • Erm. You said, yourself, _"[...] to remove libboost\_regex.dylib from the folder **so that only libboost_regex.a remained**"_. That's the folder then. Either list the full `/path/to/mylibs/libboost_regex,a` or use `-L /path/to/mylibs` ... – sehe May 27 '15 at 17:07
  • using `-L /path/to/mylibs` wasn't working, but `path/to/mylibs/libboost_regex.a` did work – Jonathan Basile May 27 '15 at 17:12