0

I have developed a C++ class which reads in a text file and store some information in provate variables. To parse the file, I use regex library. During compilation there is an error I can't understand. First I make a shared object library for my class. Afterwards I try to compile the test program. Here the error occurs: undefined reference to std::regex_iterator...

I do the compilation with the following commands on a unix machine:

g++ -c -fpic -m64 -std=c++11 Foo.h Foo.cpp

g++ -shared -m64 -std=c++11 -o libFoo.so Foo.o

g++ -m64 -std=c++11 -I. -L. -lFoo -o camelTest Foo.h main.cpp

To reproduce the error, here is a small example: example

Thanks in advance for your help

user2672165
  • 2,986
  • 19
  • 27
Fabian
  • 57
  • 9
  • 1
    Are you sure your C++ library supports regex? – user657267 Aug 01 '14 at 08:50
  • 3
    You need to use GCC 4.9 to get `` support – Jonathan Wakely Aug 01 '14 at 09:00
  • Which version of GCC are you using? GCC haven't supported the regular expressions in the standard library until quite recently. – Some programmer dude Aug 01 '14 at 09:00
  • Try Boost.Regex or Boost.Xpressive. – user541686 Aug 01 '14 at 09:01
  • I do not know if regex is supported by C++, but I think so. The error also occurs when I do not include Foo.h in the last command. – Fabian Aug 01 '14 at 09:01
  • @JonathanWakely: Is there a document somewhere explaining the particular implementation strategy of GCC's regexp implementation? I take it that this is a somewhat delicate topic, and users may wish to know about the details before deciding to move a project from their own regexp library to the standard version. – Kerrek SB Aug 01 '14 at 09:07
  • @KerrekSB, the only notes on the design are on the libstdc++ mailing list, look for posts by Tim Shen who finished the regex implementation – Jonathan Wakely Aug 01 '14 at 09:09

1 Answers1

0

g++ -m64 -std=c++11 -I. -L. -lFoo -o camelTest Foo.h main.cpp -L%PATH_TO_USED_LIB% -l%NAME_OF_LIB%

If your lib is libregexp, then %NAME_OF_LIB% == regexp

The idea is:

Flag -L(uppercase) tells gcc where your libs are.

Flag l(lowercase) tells gcc which library should gcc link to your application.

Edward
  • 304
  • 2
  • 16