compiling C library under mingw

Started by Marios Vodasover 15 years ago4 messages
#1Marios Vodas
mvodas@gmail.com

I have a library that compiles fine under linux.
But when I try to compile it under mingw on windows 7 I get the following
errors.

gcc.exe -c -O2 -I/C/PostgreSQL/9.0/include/server

-I/C/PostgreSQL/9.0/include/server/utils
-I/C/PostgreSQL/9.0/include/server/access
-I/C/PostgreSQL/9.0/include/server/port/win32 -I/C/PostgreSQL/9.0/include
-MMD -MP -MF build/Release/MinGW-Windows/mylib.o.d -o
build/Release/MinGW-Windows/mylib.o mylib.c

The previous command is successful and produces .o files (only some warnings
here like: warning: 'pg_finfo_mytype_in' redeclared without dllimport
attribute: previous dllimport ignored).
The following though gives errors.

gcc.exe -shared -o dist/Release/MinGW-Windows/libMyLib.dll

build/Release/MinGW-Windows/mylib.o

Here is the log:

build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x128): undefined

Show quoted text

reference to `errstart'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x13d): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x147): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x17b): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x180): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1be): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1c3): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1f4): undefined
reference to `errmsg'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x202): undefined
reference to `errcode'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x20e): undefined
reference to `errfinish'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x230): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x23a): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x251): undefined
reference to `Int64GetDatum'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x25c): undefined
reference to `timestamp_out'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x261): undefined
reference to `DirectFunctionCall1'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x284): undefined
reference to `Int64GetDatum'

#2Marios Vodas
mvodas@gmail.com
In reply to: Marios Vodas (#1)
Re: compiling C library under mingw

I did a little search and I found that probably there is a library (dll or
lib ???) that contains all these references. I could specify it by using
-L/C/path/to/libraries -libraryname as an option to the second gcc command,
but I have no idea what the library is and where to find it (I used
-L/C/PostgreSQL/9.0/lib -lpostgres -lpq, but it didn't work).
All those references are declared as extern in postgres source code.
Does anyone know what the library is?

On Fri, Oct 8, 2010 at 12:27 PM, Marios Vodas <mvodas@gmail.com> wrote:

Show quoted text

I have a library that compiles fine under linux.
But when I try to compile it under mingw on windows 7 I get the following
errors.

gcc.exe -c -O2 -I/C/PostgreSQL/9.0/include/server

-I/C/PostgreSQL/9.0/include/server/utils
-I/C/PostgreSQL/9.0/include/server/access
-I/C/PostgreSQL/9.0/include/server/port/win32 -I/C/PostgreSQL/9.0/include
-MMD -MP -MF build/Release/MinGW-Windows/mylib.o.d -o
build/Release/MinGW-Windows/mylib.o mylib.c

The previous command is successful and produces .o files (only some
warnings here like: warning: 'pg_finfo_mytype_in' redeclared without
dllimport attribute: previous dllimport ignored).
The following though gives errors.

gcc.exe -shared -o dist/Release/MinGW-Windows/libMyLib.dll

build/Release/MinGW-Windows/mylib.o

Here is the log:

build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x128): undefined

reference to `errstart'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x13d): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x147): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x17b): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x180): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1be): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1c3): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1f4): undefined
reference to `errmsg'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x202): undefined
reference to `errcode'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x20e): undefined
reference to `errfinish'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x230): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x23a): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x251): undefined
reference to `Int64GetDatum'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x25c): undefined
reference to `timestamp_out'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x261): undefined
reference to `DirectFunctionCall1'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x284): undefined
reference to `Int64GetDatum'

#3Magnus Hagander
magnus@hagander.net
In reply to: Marios Vodas (#2)
Re: compiling C library under mingw

You need to link to postgres.exe - either directly or by manually
creating an import library.

//Magnus

On Sat, Oct 9, 2010 at 11:40, Marios Vodas <mvodas@gmail.com> wrote:

I did a little search and I found that probably there is a library (dll or
lib ???) that contains all these references. I could specify it by using
-L/C/path/to/libraries -libraryname as an option to the second gcc command,
but I have no idea what the library is and where to find it (I used
-L/C/PostgreSQL/9.0/lib -lpostgres -lpq, but it didn't work).
All those references are declared as extern in postgres source code.
Does anyone know what the library is?

On Fri, Oct 8, 2010 at 12:27 PM, Marios Vodas <mvodas@gmail.com> wrote:

I have a library that compiles fine under linux.
But when I try to compile it under mingw on windows 7 I get the following
errors.

gcc.exe -c -O2 -I/C/PostgreSQL/9.0/include/server
-I/C/PostgreSQL/9.0/include/server/utils
-I/C/PostgreSQL/9.0/include/server/access
-I/C/PostgreSQL/9.0/include/server/port/win32 -I/C/PostgreSQL/9.0/include
-MMD -MP -MF build/Release/MinGW-Windows/mylib.o.d -o
build/Release/MinGW-Windows/mylib.o mylib.c

The previous command is successful and produces .o files (only some
warnings here like: warning: 'pg_finfo_mytype_in' redeclared without
dllimport attribute: previous dllimport ignored).
The following though gives errors.

gcc.exe -shared -o dist/Release/MinGW-Windows/libMyLib.dll
build/Release/MinGW-Windows/mylib.o

Here is the log:

build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x128): undefined
reference to `errstart'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x13d): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x147): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x17b): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x180): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1be): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1c3): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1f4): undefined
reference to `errmsg'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x202): undefined
reference to `errcode'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x20e): undefined
reference to `errfinish'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x230): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x23a): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x251): undefined
reference to `Int64GetDatum'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x25c): undefined
reference to `timestamp_out'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x261): undefined
reference to `DirectFunctionCall1'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x284): undefined
reference to `Int64GetDatum'

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#4Marios Vodas
mvodas@gmail.com
In reply to: Magnus Hagander (#3)
Re: compiling C library under mingw

It is an exe don't I need a dll?
Can you get more specific on "either directly or by manually creating an
import library"? What I understand by directly is that I should rename
postgres.exe to postgres.dll.
Thank you for responding so quickly.

On Sat, Oct 9, 2010 at 12:44 PM, Magnus Hagander <magnus@hagander.net>wrote:

Show quoted text

You need to link to postgres.exe - either directly or by manually
creating an import library.

//Magnus

On Sat, Oct 9, 2010 at 11:40, Marios Vodas <mvodas@gmail.com> wrote:

I did a little search and I found that probably there is a library (dll

or

lib ???) that contains all these references. I could specify it by using
-L/C/path/to/libraries -libraryname as an option to the second gcc

command,

but I have no idea what the library is and where to find it (I used
-L/C/PostgreSQL/9.0/lib -lpostgres -lpq, but it didn't work).
All those references are declared as extern in postgres source code.
Does anyone know what the library is?

On Fri, Oct 8, 2010 at 12:27 PM, Marios Vodas <mvodas@gmail.com> wrote:

I have a library that compiles fine under linux.
But when I try to compile it under mingw on windows 7 I get the

following

errors.

gcc.exe -c -O2 -I/C/PostgreSQL/9.0/include/server
-I/C/PostgreSQL/9.0/include/server/utils
-I/C/PostgreSQL/9.0/include/server/access
-I/C/PostgreSQL/9.0/include/server/port/win32

-I/C/PostgreSQL/9.0/include

-MMD -MP -MF build/Release/MinGW-Windows/mylib.o.d -o
build/Release/MinGW-Windows/mylib.o mylib.c

The previous command is successful and produces .o files (only some
warnings here like: warning: 'pg_finfo_mytype_in' redeclared without
dllimport attribute: previous dllimport ignored).
The following though gives errors.

gcc.exe -shared -o dist/Release/MinGW-Windows/libMyLib.dll
build/Release/MinGW-Windows/mylib.o

Here is the log:

build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x128): undefined
reference to `errstart'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x13d): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x147): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x17b): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x180): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1be): undefined
reference to `timestamp_in'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1c3): undefined
reference to `DirectFunctionCall3'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x1f4): undefined
reference to `errmsg'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x202): undefined
reference to `errcode'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x20e): undefined
reference to `errfinish'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x230): undefined
reference to `_imp__CurrentMemoryContext'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x23a): undefined
reference to `MemoryContextAlloc'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x251): undefined
reference to `Int64GetDatum'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x25c): undefined
reference to `timestamp_out'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x261): undefined
reference to `DirectFunctionCall1'
build/Release/MinGW-Windows/mylib.o:mylib.c:(.text+0x284): undefined
reference to `Int64GetDatum'

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/