lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

compilation issue on windows #111

Open smoothdeveloper opened 10 years ago

smoothdeveloper commented 10 years ago

This is how it goes with current master:

cabal configure
cabal build --verbose
Component build order: library
creating dist\build
creating dist\build\autogen
Building postgresql-simple-0.4.2.2...
Preprocessing library postgresql-simple-0.4.2.2...
Building library...
creating dist\build
C:\dev\bin\haskell-2013.2.0.0\bin\ghc.exe --make -fbuilding-cabal-package -O -outputdir dist\build -odir dist\build -hidir dist\build -stubdir dist\build -i -idist\build -isrc -idist\build\autogen -Idist\build\autogen -Idist\build -optP-include -optPdist\build\autogen\cabal_macros.h -package-name postgresql-simple-0.4.2.2 -hide-all-packages -package-db dist\package.conf.inplace -package-id aeson-0.6.2.1-878117afb106a49080d570b0d0c89775 -package-id attoparsec-0.10.4.0-b7d4a7202f217cfeff7b1b1d6379bc87 -package-id base-4.6.0.1-f0c2cc6dcf0e12bf75312a2e7f354095 -package-id blaze-builder-0.3.3.2-a5c5f6db86ce4ef94f55fe01154717b2 -package-id blaze-textual-0.2.0.9-aa8f5b545854c0bf278d4bf1afa0aff7 -package-id bytestring-0.10.0.2-c8fbf42ac6de7e76dd9245b3f7a2fa84 -package-id containers-0.5.0.0-216fcd375644c41421c5f14613e6b5af -package-id hashable-1.1.2.5-e8326d7b0c6af07b9139e791b5b3ad95 -package-id postgresql-libpq-0.9.0.1-822b83f11d3322cf00f1c3a90902628c -package-id scientific-0.2.0.2-2ae95b341de67ca0889d39ff72f50fb9 -package-id template-haskell-2.8.0.0-42f1e6e55511ef4dff7e4249580faf8f -package-id text-0.11.3.1-a8ece294fe3000125614f30af4cc5e8b -package-id time-1.4.0.1-ecfe3938f222e49c5674480c0da9b8a4 -package-id transformers-0.3.0.0-df161533671a3b9bce217538864873c4 -package-id uuid-1.3.3-7578bb0016e132286aab139511e37350 -package-id vector-0.10.0.1-de357a28bd1947d0c1ee9b730f605fb0 -XHaskell98 -XDoAndIfThenElse -XOverloadedStrings -XBangPatterns -XViewPatterns -XTypeOperators Database.PostgreSQL.Simple Database.PostgreSQL.Simple.Arrays Database.PostgreSQL.Simple.BuiltinTypes Database.PostgreSQL.Simple.Copy Database.PostgreSQL.Simple.FromField Database.PostgreSQL.Simple.FromRow Database.PostgreSQL.Simple.LargeObjects Database.PostgreSQL.Simple.HStore Database.PostgreSQL.Simple.HStore.Internal Database.PostgreSQL.Simple.Notification Database.PostgreSQL.Simple.Ok Database.PostgreSQL.Simple.SqlQQ Database.PostgreSQL.Simple.Time Database.PostgreSQL.Simple.Time.Internal Database.PostgreSQL.Simple.ToField Database.PostgreSQL.Simple.ToRow Database.PostgreSQL.Simple.Transaction Database.PostgreSQL.Simple.TypeInfo Database.PostgreSQL.Simple.TypeInfo.Macro Database.PostgreSQL.Simple.TypeInfo.Static Database.PostgreSQL.Simple.Types Database.PostgreSQL.Simple.Errors Database.PostgreSQL.Simple.Internal Database.PostgreSQL.Simple.Compat Database.PostgreSQL.Simple.HStore.Implementation Database.PostgreSQL.Simple.Time.Implementation Database.PostgreSQL.Simple.TypeInfo.Types -Wall -fno-warn-name-shadowing
[ 1 of 32] Compiling Database.PostgreSQL.Simple.TypeInfo.Types ( src\Database\PostgreSQL\Simple\TypeInfo\Types.hs, dist\build\Database\PostgreSQL\Simple\TypeInfo\Types.o ) [flags changed]
[ 2 of 32] Compiling Database.PostgreSQL.Simple.Time.Implementation ( src\Database\PostgreSQL\Simple\Time\Implementation.hs, dist\build\Database\PostgreSQL\Simple\Time\Implementation.o ) [flags changed]
[ 3 of 32] Compiling Database.PostgreSQL.Simple.Time.Internal ( src\Database\PostgreSQL\Simple\Time\Internal.hs, dist\build\Database\PostgreSQL\Simple\Time\Internal.o ) [flags changed]
[ 4 of 32] Compiling Database.PostgreSQL.Simple.SqlQQ ( src\Database\PostgreSQL\Simple\SqlQQ.hs, dist\build\Database\PostgreSQL\Simple\SqlQQ.o ) [flags changed]
[ 5 of 32] Compiling Database.PostgreSQL.Simple.Time ( src\Database\PostgreSQL\Simple\Time.hs, dist\build\Database\PostgreSQL\Simple\Time.o ) [flags changed]
[ 6 of 32] Compiling Database.PostgreSQL.Simple.TypeInfo.Static ( src\Database\PostgreSQL\Simple\TypeInfo\Static.hs, dist\build\Database\PostgreSQL\Simple\TypeInfo\Static.o ) [flags changed]
[ 7 of 32] Compiling Database.PostgreSQL.Simple.BuiltinTypes ( src\Database\PostgreSQL\Simple\BuiltinTypes.hs, dist\build\Database\PostgreSQL\Simple\BuiltinTypes.o ) [flags changed]
[ 8 of 32] Compiling Database.PostgreSQL.Simple.Arrays ( src\Database\PostgreSQL\Simple\Arrays.hs, dist\build\Database\PostgreSQL\Simple\Arrays.o ) [flags changed]
[ 9 of 32] Compiling Database.PostgreSQL.Simple.Types ( src\Database\PostgreSQL\Simple\Types.hs, dist\build\Database\PostgreSQL\Simple\Types.o ) [flags changed]
[10 of 32] Compiling Database.PostgreSQL.Simple.TypeInfo.Macro ( src\Database\PostgreSQL\Simple\TypeInfo\Macro.hs, dist\build\Database\PostgreSQL\Simple\TypeInfo\Macro.o ) [flags changed]
[11 of 32] Compiling Database.PostgreSQL.Simple.ToField[boot] ( src\Database\PostgreSQL\Simple\ToField.hs-boot, dist\build\Database\PostgreSQL\Simple\ToField.o-boot ) [flags changed]
[12 of 32] Compiling Database.PostgreSQL.Simple.ToRow[boot] ( src\Database\PostgreSQL\Simple\ToRow.hs-boot, dist\build\Database\PostgreSQL\Simple\ToRow.o-boot ) [flags changed]
[13 of 32] Compiling Database.PostgreSQL.Simple.ToField ( src\Database\PostgreSQL\Simple\ToField.hs, dist\build\Database\PostgreSQL\Simple\ToField.o ) [flags changed]
[14 of 32] Compiling Database.PostgreSQL.Simple.ToRow ( src\Database\PostgreSQL\Simple\ToRow.hs, dist\build\Database\PostgreSQL\Simple\ToRow.o ) [flags changed]
[15 of 32] Compiling Database.PostgreSQL.Simple.Ok ( src\Database\PostgreSQL\Simple\Ok.hs, dist\build\Database\PostgreSQL\Simple\Ok.o ) [flags changed]
[16 of 32] Compiling Database.PostgreSQL.Simple.Internal ( src\Database\PostgreSQL\Simple\Internal.hs, dist\build\Database\PostgreSQL\Simple\Internal.o ) [flags changed]
[17 of 32] Compiling Database.PostgreSQL.Simple.LargeObjects ( src\Database\PostgreSQL\Simple\LargeObjects.hs, dist\build\Database\PostgreSQL\Simple\LargeObjects.o ) [flags changed]
[18 of 32] Compiling Database.PostgreSQL.Simple.Notification ( src\Database\PostgreSQL\Simple\Notification.hs, dist\build\Database\PostgreSQL\Simple\Notification.o ) [flags changed]
[19 of 32] Compiling Database.PostgreSQL.Simple.Errors ( src\Database\PostgreSQL\Simple\Errors.hs, dist\build\Database\PostgreSQL\Simple\Errors.o ) [flags changed]
[20 of 32] Compiling Database.PostgreSQL.Simple.Compat ( src\Database\PostgreSQL\Simple\Compat.hs, dist\build\Database\PostgreSQL\Simple\Compat.o ) [flags changed]
[21 of 32] Compiling Database.PostgreSQL.Simple.Transaction ( src\Database\PostgreSQL\Simple\Transaction.hs, dist\build\Database\PostgreSQL\Simple\Transaction.o ) [flags changed]
[22 of 32] Compiling Database.PostgreSQL.Simple.FromField[boot] ( src\Database\PostgreSQL\Simple\FromField.hs-boot, dist\build\Database\PostgreSQL\Simple\FromField.o-boot )
[23 of 32] Compiling Database.PostgreSQL.Simple.FromRow[boot] ( src\Database\PostgreSQL\Simple\FromRow.hs-boot, dist\build\Database\PostgreSQL\Simple\FromRow.o-boot )
[24 of 32] Compiling Database.PostgreSQL.Simple[boot] ( src\Database\PostgreSQL\Simple.hs-boot, dist\build\Database\PostgreSQL\Simple.o-boot )
[25 of 32] Compiling Database.PostgreSQL.Simple.TypeInfo ( src\Database\PostgreSQL\Simple\TypeInfo.hs, dist\build\Database\PostgreSQL\Simple\TypeInfo.o ) [flags changed]
[26 of 32] Compiling Database.PostgreSQL.Simple.FromField ( src\Database\PostgreSQL\Simple\FromField.hs, dist\build\Database\PostgreSQL\Simple\FromField.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package bytestring-0.10.0.2 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package binary-0.7.1.0 ... linking ... done.
Loading package byteable-0.1.1 ... linking ... done.
Loading package cryptohash-0.11.1 ... linking ... done.
Loading package text-0.11.3.1 ... linking ... done.
Loading package hashable-1.1.2.5 ... linking ... done.
C:/dev/bin/haskell-2013.2.0.0/mingw/bin/../lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

I've tried building various tags, and the first which builds is version 0.3.6, failing from 0.3.7

I've to figure out what dependency in FromField might cause the trouble, as I believe it's related to this file (according to the build output which fails while compiling this module.

lpsmith commented 10 years ago

Well, I'm going to guess that aa96786e7bb98d75ba4c220ecf57e17c38f843fb and 1a390f5e1129edae493605a4101098eb844a58a7 triggered the problem you are seeing. I feel pretty confident about that guess.

The true cause of the problem seems to be that, for whatever reason, Template Haskell isn't working due to a linking error. Unfortunately I don't know much about why that might be. Can you compile other modules/packages that use Template Haskell?

lpsmith commented 10 years ago

Here's an idea, have you actually been able to use vanilla postgresql-libpq to successfully connect to a database? And are you using libpq 9.0 or later?

113 looks exactly the same, except for the error message, which may be misleading.

smoothdeveloper commented 10 years ago

Thanks for further review.

Yes I've been using yesod and other packages which do use Template Haskell.

I'll give a shot at postgresql-libpq itself and report here, I'm using 9.0.2 release of postgresql which I referenced in order to compile the haskell package.

lpsmith commented 10 years ago

Ok, if postgresql-libpq does turn out to be a problem, you may or may not find #66 to be helpful in getting it to work. If this is the problem, I would definitely be interested in your review of the instructions there.

smoothdeveloper commented 10 years ago

I'm getting this issue using postgresql-libpq

*TestPg> connectdb connectionString
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package bytestring-0.10.0.2 ... linking ... done.
Loading package postgresql-libpq-0.9.0.1 ... <interactive>: Unknown PEi386 secti
on name `.idata$4' (while processing: C:/dev/bin/POSTGR~1.1/lib\libpq.a)
ghc.exe: panic! (the 'impossible' happened)
  (GHC version 7.6.3 for i386-unknown-mingw32):
        loadArchive "C:/dev/bin/POSTGR~1.1/lib\\libpq.a": failed

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

I'm not sure how I should check the libpq.a contains what it's supposed to contain but it seems to be the one which come with postgresql release (it's 9.2.4.1 BTW), there might be issue with conflicting versions of mingw between haskell platform and the one used to compile postgresql binaries?

This stackoverflow question with same error message mention that I would need to define a linker script somewhere:

http://stackoverflow.com/questions/13209425/how-to-resolve-the-ghc-error-unknown-pei386-section-name-idata4-on-window

lpsmith commented 10 years ago

Yeah, I'm pretty sure that's causing the postgresql-simple compilation error. As to what's causing this error, I dunno. Where did you get the libpq object code you are using? Did you compile it yourself or did you download a precompiled object from somewhere?

Several people are successfully using postgresql-libpq on Windows. Have you tried the description that Joey Adams posted about how he does it in #66?

smoothdeveloper commented 10 years ago

My bad, I was trying to link with x64 binaries...

I'm not sure what could be done upper in the chain so it won't come with this misleading linker error message.

So applying the instructions from #66 plainly works now :)

Hopefully, if someone hits the same issue / overlook, this page will provide the solution.

lpsmith commented 10 years ago

Oh, no problem. I am happy you got it working, and I am aware that a number of people have had trouble with postgresql-libpq on Windows. =)

lpsmith commented 10 years ago

Ok, inspired partly by this report and several other similar reports, I did open up lpsmith/postgresql-libpq#20 and lpsmith/postgresql-libpq#21 to help avoid/diagnose these problems in the future.