1

I'm new to Eclipse environment and I'm trying to write a C program in Eclipse installed in Windows 10. Compiler I use is MinGW latest version installed through MSYS2. The program I've written has got regular expressions used in it. When I try to build the code, I get the following errors-

21: undefined reference to regcomp' 35: undefined reference toregexec' enter image description here

Can anyone help me resolve this issue??

SayAz
  • 751
  • 1
  • 9
  • 16
Priya.D
  • 21
  • 5
  • It's caused by [Failure to link against appropriate libraries/object files or compile implementation files](https://stackoverflow.com/a/12574400/1362568) – Mike Kinghan May 22 '20 at 18:00
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan May 22 '20 at 18:00

1 Answers1

0

If you have #include <regex.h> in your code and it compiles then it looks like you have the library installed.

But undefined reference to 'regexec' is a linker error, which means you're not linking with the library that you are calling functions of.

So you need to link with this library, probably by adding the linker flag -lregex.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • I'm sorry for asking these minor details, but I'm new to Eclipse and coding in Windows environment. May I know where'd I get the path for that linker flag? I use MinGW for compilation. So, is there any command to get the path of that -iregex linker flag alone, so that I can add it to my Project in Eclipse? – Priya.D Jun 24 '20 at 13:43
  • I'm don't use Eclipse myself, but this question has been answered before, so if you look for it it 's not that hard to find. Maybe something like this: https://stackoverflow.com/questions/19502795/compiler-flags-in-eclipse – Brecht Sanders Jun 24 '20 at 16:04