How do I deal with "undefined reference to `regcomp'" error - c

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??

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.

Related

How to link Libb64 libraries at compiling?

I need to use Base64 encoding/decoding in my C program and I tried to use some functions of Libb64 library. When I compile the code, it gives the error below:
... undefined reference to 'base64_init_encodestate'
... undefined reference to 'base64_encode_block'
... undefined reference to 'base64_encode_blockend'
collect2: error: ld returned 1 exit status
I tried to compile code with parameters like -libb64, -llibb64, -lbase64 but it didn't work.
What is the link parameter should I add when compiling? Or are there any ways solve this problem?
You can try -lb64. It is a guess and may not work. Try it and if it does not work I will actually install and answer with accuracy.
Edit 1: Although it solved your problem but this is not real answer. Whenever you install a library on Linux(it is an assumption that you are using Linux) then it gets installed by the name of libxyz.so and your switch to compiler/linker should be -lxyz. In case you do not know the name of library then check with something like Synaptic to know what files are installed by that package. If you are installing by source then look at the libraries generated in the source directory from where you are installing. I do not know exact commands for yum, apt-get or pacman or emerge which are package managers for different distributions but you can read the man page and know that as well.

undefined reference to 'gnutls_...' functions

So for an assignment I need to use GnuTLS. I have downloaded gnutls by following this guide http://www.bauer-power.net/2014/06/how-to-install-gnutls-3123-from-source.html
However, using any of the gnutls functions, similar to how they are used in the official gnutls documentation (http://www.gnutls.org/manual/html_node/Client-examples.html), displays several errors after building. All errors follow this format:
...pathtofile:line#/..undefined reference to 'gnutls_...'
I understand that this might be a linking problem, however I am quite new to this type of environment. What should I do? I have tried to install gnutls again several times.
I am using Ubuntu 14.04, gnutls-3.1.23 and eclipse Luna.
Thanks in advance.
You probably have an error on your link line.
Add the flag -lgnutls to the ld command (or, if just one C file, the compile line).

When I try to run MPI code, I get undefined reference to MPI_File_Seek#12, What might be the reason?

I've been trying to run the code from https://github.com/dungtn/mpi-floyd/blob/master/floyd2d.c in my system. I'm using CodeBlocks IDE and MS-Mpi. When I try to compile the code, it says undefined reference to MPI_file_seek#12. Does this mean MS mpi does not support this function or why does this happen?
This usually happens if you are trying to link 32-bit code with 64-bit libraries. The fact that the unresolved symbol has #12 in its name means that the compiler is expecting that MPI_File_seek is an stdcall function. stdcall is mainly used for DLL functions and only on x86 (x64 uses a different calling convention similar to fastcall). If you are linking against the 64-bit import library of MS-MPI, the decorated symbol won't be found in the library and such an error will occur.
Double check what version of MS-MPI you have and also your project settings and make sure that both have the same "bitness".
Change the project settings in Code::Blocks to a C project (rather than C++ project, what you have currently). It may be easier to create a brand new C project and import the file there. Double check that Code::Blocks in running gcc and not g++ to compile your code (floyd2d.c).
If it still doesn't work, please post the full compiler and linker output of Code::Blocks, including the commands run and their output messages.

Eclipse CDT - errors: "undefined reference to n"?

I'm not entirely sure if this belongs here or on electronics.stackexchange.com, but since this is to do with IDE setup, and compilation, I believe this is the best place to ask my question.
I've got a C project setup in Eclipse CDT. It uses the Sourcery CodeBench Lite ARM toolchain from Mentor Graphics. I've got the Eclipse CDT, as well as GNU ARM Eclipse plugins installed, and trying to setup the ST.com STM32F4 Discovery examples to compile in Eclipse CDT.
When compiling, the compiler is outputting over 200 errors (shortened for brevity):
.../main.c:75: undefined reference to `STM_EVAL_PBInit'
.../main.c:77: undefined reference to `STM_EVAL_LEDInit'
.../main.c:78: undefined reference to `STM_EVAL_LEDInit'
.../main.c:79: undefined reference to `STM_EVAL_LEDInit'
.../main.c:80: undefined reference to `STM_EVAL_LEDInit'
.../main.c:83: undefined reference to `RCC_GetClocksFreq'
.../main.c:86: undefined reference to `STM_EVAL_PBGetState'
.../main.c:89: undefined reference to `STM_EVAL_LEDOn'
.../main.c:90: undefined reference to `STM_EVAL_LEDOn'
.../main.c:91: undefined reference to `STM_EVAL_LEDOn'
.../main.c:92: undefined reference to `STM_EVAL_LEDOn'
Nearly all these items are defined in stm32f4_discovery.h, but for some reason, they are not being resolved during compilation.
I've checked, and double checked that the file is made available C/C++ General > Paths and Symbols, Includes tab, but not sure why things aren't working out.
The project is available on GitHub, for anyone wanting to checkout and try the compilation themselves.
I also created a ticket on Github, as I didn't want to flood here with output information.
Simply clone https://github.com/josefvanniekerk/stm32f4-discovery.git, import stm32f4-discovery/projects/demonstration into Eclipse CDT, and try the compilation.
The Sourcery CodeBench Lite toolchain is compiled on Mac OS X from arm-cs-tools-build.sh, and the Eclipse GNU ARM plugin is required, and can be installed into Eclipse using their update site
Turns out I just needed to add the external sources under
C/C++ General > Paths and Symbols > Source Location
Still some errors, but not relating to this question anymore. :)

linker error in c

how can i resolve a linker error in c?
this is the error message:
undefined reference to HPDF_Page_SetRGBStroke
If you are using an external library, you have to tell the linker that it should be included. It has no means of automagically finding out what you're using there.
Using gcc you can do this by compiling the program with -llibrary.
Apparently, you're trying to use a routine from the libharu PDF library, and it seems you're not linking against this library.
How exactly you would resolve this depends on the toolchain you're using -- under gcc, you would have to add a -lharu option or similar to the linker options.

Resources