linker error in c - 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.

Related

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.

What does this linking error mean?

When I was compiling a new software, I encountered a bunch of errors emitted by ld.
/usr/lib/libstreamanalyzer.so.0: undefined reference to `xmlSAXUserParseMemory#LIBXML2_2.4.30'
/usr/lib/libstreamanalyzer.so.0: undefined reference to `xmlCtxtResetPush#LIBXML2_2.6.1'
/usr/lib/libstreamanalyzer.so.0: undefined reference to `xmlCreatePushParserCtxt#LIBXML2_2.4.30'
This seems to be confusing. Linker is supposed to be looking for symbols in objects, not library names, but it seems in this case those before the # is the function name/symbol, and LIBXML2_2.6.1 is a library name. And for dynamic library, the soname x.y.z version should only matter in dynamic linking stage, that is when the executable actually runs.
So what does this error really means, and what part of the above assumptions are wrong?
Edit:
The problem appears after installing libxml2 2.7.8. It is gone after libxml2 is upgraded to 2.9.1.
When I was compiling a new software, I encountered a bunch of errors
No, you didn't. You encountered errors when linking, which is different from compiling.
Linker is supposed to be looking for symbols in objects
UNIX linkers also look for symbols in libraries (both archive and shared).
LIBXML2_2.6.1 is a library name
No, it's not. It's a symbol version, which happens to reflect the library in which that symbol was defined.
So what does this error really means
This error means: when libstreamanalyzer.so.0 was linked, it was linked against a library (most likely libxml2.so) that provided versioned symbols xmlSAXUserParseMemory#LIBXML2_2.4.30, etc.
You are now linking your binary against some other version of libxml2, one which does not provide these symbols, and your binary will not work.

Linking gfortran libraries to c++ program in CodeBlocks under Ubuntu

I have an Ubuntu under Vmware, and use Code::Blocks, as I am not a very powerful command line user
and prefer IDE to Vim+console.
I am trying to compile a program which uses a c++ wrapper to fortran library.
However compiling gives me the following errors:
undefined reference to `_gfortran_compare_string'
There are a lot of errors of this type and a bunch of other similar to this one.
I have gfortran 4.6.3. I found searching that it is probably a linking problem, and people say to
use -lgfortran option for linker. When I add this to linker options in the Code::Blocks it does not change anything, errors continue. So, here are some question:
Is this a correct option for linker?
May be I have to give linker a direct path to the fortran library?
How do I find where are the fortran libraries installed? (I don't know a lot about linux ((( )
What am I doing wrong and how to fix it.
Have you added gfortran as a library to linked to your project or lgfortran? The l is just an option for the g++ for linking the library gfortran to your code. I am not familar with Code::Blocks but you should look for a place where you can enter libraries you want to use and add the gfortran directly.
My guess is that the Code::Blocks side can help you to find this place.
Kim Kulling
My guess is something like /bin/lib /usr/lib or /usr/local/lib. Just take a look into your filesystem. Unfortunately I do not have a Linuix at work. Maybe someone else?
Kim Kulling

Using pcre in a c program on windows

I am trying to build an appliction based upon the pcredemo application. When I try and compile the application in Windows I get the following compiler errors.
undefined reference to `_imp__pcre_compile'|
undefined reference to `_imp__pcre_exec'|
undefined reference to `_imp__pcre_free'|
Am I missing some .dll files or something?
Those are linker errors. You need to make sure that you are passing the PCRE .lib files to the linker. Another possible problem could be that your compiler/linker is using a different .lib file format from that used to build the PCRE .lib files.
If you are linking PCRE statically, you need to #define PCRE_STATIC before compiling.

How prevent from dynamic relocation (rela.dyn)?

I am trying to run a simple program on an powerpc embedded system without any operating system. I am using GNU compiler-linker tools and PSIM as simulator. I've written my own very simple Linker Directive file.
I've used a global variable in my static library and want to use that variable in my sample program. But while linking the sample program GNU ld gives an error and stops. It says that it cannot find rela.dyn in linker directive file. Actually I do not want to use dynamically relocatable library, because I dont have a dynamic loader. What am I doing wrong?
Hard to say without more info. If you don't have an underlying OS, did you use -ffreestanding to avoid linking in the platform runtime?
Edit: -ffreestanding requires -shared? -ffreestanding means to compile to a non-hosted environment. How can such an environment support shared libraries?
-ffreestanding, as Solar says. If that fails, run ld with the --verbose option to see exactly what it is trying to link in: that will enable you to debug further.

Resources