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.
Related
I added to Visual studio Project->Properties->Linker->Input->Additional Dependencies the x.lib file. My build was successful but program didnt start because after start it wrotes: The program cant start because of x.dll is missing from your computer. Why is it looking for x.dll and not x.lib?
For dynamic linking:
x.lib is used for compiling, which contains the linking information of library functions. When compiling, compiler just check whether these functions exist. To understand it simply, compiling will give the way to locating these functions in dll files.
While x.dll is dynamic link library which contains the implementations (maybe not that accurate) of these functions. If you didn't set dll right, the program cannot execute the corresponding functions. dll is the actually executable file, not lib.
I am fairly new to C and I am trying to include a external library without using any IDE, only text-editor and the minGW compiler on windows cmd. The library is libPNG in this case, I would really like to understand how the process work not only for this library.
If there is a better way (and easier) to do this, I would also like to know.
You have two parts to take care of:
compilation,
linking.
Compilation
In compilation, when you transform source files in object files, your compiler must know what are the functions provided by the external library.
You could declare each function you use or you can include the library header file(s) in your code:
#incude <library_file.h>
It's not enough, you will have to tell your compiler where it can find this file:
-I<path_to_lib_folder> with gcc
/I<path_to_lib_folder> with cl (the visual studio compiler)
Linking
In linking process, you put the object and library files together to construct an executable file.
You need to tell the linker
what files it must use and
where it can find the library file
You tell the linker what files to use with the -l options, for instance, -lfoo will tell it to search for the libfoo.so lib
Note: with cl you can tell specify which library to use directly in your source code with #pragma comment (lib, "libfoo.lib")
Add you specify where with:
-L<path_to_lib_folder> with gcc
/LIBPATH:<path_to_lib_folder> with link (the visual studio linker)
You can also use dynamic linking, but let's start with the first step.
I've been trying to link to a third-party DLL. I've tried in 3 different ways: by compiling C in Cygwin, by compiling C++ in Visual Studio and by compiling C# in Visual Studio. Everytime I compile the programs, I get the following errors:
Cygwin: undefined reference to '__imp__IEC61850_Create'
Visual S: LNK2019: unresolved external symbol '__imp__IEC61850_Create'
As you might have gathered, I am trying to call the function 'IEC61850_Create' which is found in the DLL, but it always shows up in errors with the '__imp__' prefix. As the DLL is third-party, I can't view the source. In other places I have searched, people usually talk about an accompanying .o or .lib file. In this case, the only resource I have is the .dll.
Has anyone else experienced something like this, or know how I can link to the library? I can provide sample code if needed.
Thanks.
You really need to link to the .lib file, because only it has the __imp__ stubs needed for static linking.
However, what you can do is to create a .def file and use lib to convert it into a .lib file.
Alternatively you can create a dummy project with empty functions to create a .dll and a .lib file, link to the .lib file, but then use the real .dll with the actual program.
For more information you could read Microsoft KB Article 131313.
In the process of porting a C project from Linux to Windows
Have installed MinGW
Have compiled my shared library using a Makefile
This produces libExample.so
Now I'm trying to link this shared library to a test harness so I can see if everything is working as expected
In the harness Makefile I specify the location of the library, e.g. -LE:/libExample_dir and the name of the library -lExample
but its complaining it cannot find the library, i.e. linker is failing with cannot find -lExample - is there some difference with windows regarding .so and .dll or perhaps pathnames that I am missing?
You need to fix the make file so shared libraries are generated with a .dll extension.
If I had to guess, I'd say that while renaming the generated file is enough to make the linker happy, the loader still expects the .so extension because that's the name that was compiled in...
Using MinGw to compile C code to produce a shared library, remember to rename the output from libExample.so to libExample.dll otherwise the linker will fail to find your library
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.