Re: [pcre-dev] [Bug 1204] Undefined reference to `_imp__pcre…

Góra strony
Delete this message
Autor: Graycode
Data:  
Dla: pcre-dev
Temat: Re: [pcre-dev] [Bug 1204] Undefined reference to `_imp__pcre_compile' when using DEV-C++
Sorry I can't reply directly to the bug list, trying that never has
worked for me.

On Mon, 30 Jan 2012, Zoltan Herczeg wrote:

> Pcre does not have a utils.c source file. And I am not aware of any _imp__
> prefix in the library. Is this the only error?


This is a Windows thing. Items (functions or data) that are exported
from a build of a DLL are prepended with '_imp__' for later linkage.
Exported means they are externally visible and accessible when the DLL
will be used at run-time.

In this case utils.c is likely the author's own file. The error was:

[Linker error] utils.o:utils.c:(.text+0x34e): undefined reference to
`_imp__pcre_compile'

I interpret this as utils.c contains code that invokes pcre_compile().
At link time it was not resolved. The author's file did not specify a
definition for PCRE_STATIC, and so its inclusion of pcre.h indicates
that pcre_compile() is an exported item from a DLL. If the author had
defined PCRE_STATIC then the linker would not have been looking for it
with the '_imp__' prefix name.

See pcre.h line# 54:
#if defined(_WIN32) && !defined(PCRE_STATIC)

So anyway the linker is looking for something named _imp__pcre_compile.
It's looking for an import of an exported function that was named
pcre_compile().

I think the cause of this problem is either:

1) The PCRE library was built as a DLL but its resulting ".lib" is not
in a lib path where the linker can find it. Or alternatively perhaps
the DLL's ".lib" was not specified to the linker. When building that
PCRE as a static library, a (#define PCRE_STATIC) would have been
specified in config.h or a /D directive during compilation.

2) The PCRE library was built as a static library (not as a DLL) but
the application (utils.c) is being compiled with a pcre.h / pcrecpp.h
that indicates the library was built as a DLL. For a static PCRE
library the application should have defined PCRE_STATIC prior to
including pcre.h or pcrecpp.h.

Consideration for this is touched upon in document NON-UNIX-USE,
section "LINKING PROGRAMS IN WINDOWS ENVIRONMENTS".

If it helps, please mention relevant parts to the bug report.
PS: I don't know anything about "DEV-C++".


Regards,
Graycode