arcapos / luapgsql

Lua binding for PostgreSQL
108 stars 24 forks source link

libpq.dll: file not recognized: File format not recognized #47

Closed mrkskwsnck closed 3 years ago

mrkskwsnck commented 6 years ago

I am trying to install luapgsql via LuaRocks on my Windows 10 machine. Unfortunately it keeps failing.

C:\> luarocks install --local luapgsql PQ_DIR=C:/pgsql PQ_INCDIR=C:/pgsql/include
Installing https://luarocks.org/luapgsql-1.6.1-1.rockspec
mingw32-gcc -O2 -c -o luapgsql.o -IC:/lua/include luapgsql.c -IC:/pgsql/include
luapgsql.c: In function 'get_param':
luapgsql.c:509:34: warning: implicit declaration of function 'htobe64' [-Wimplicit-function-declaration]
    *(uint64_t *)paramValues[n] = htobe64(swap.i);
                                  ^~~~~~~
mingw32-gcc -shared -o pgsql.dll luapgsql.o -LC:/pgsql/lib -lpq C:/lua/lua53.dll -lm
C:/pgsql/lib/libpq.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module pgsql.dll

My system

What am I missing?

mbalmer commented 6 years ago

I am sorry, but Windows is not a system we support.

Am 05.10.2017 um 15:33 schrieb Markus Kwaśnicki notifications@github.com:

I am trying to install luapgsql via LuaRocks on my Windows 10 machine. Unfortunately it keeps failing.

C:> luarocks install --local luapgsql PQ_DIR=C:/pgsql PQ_INCDIR=C:/pgsql/include Installing https://luarocks.org/luapgsql-1.6.1-1.rockspec mingw32-gcc -O2 -c -o luapgsql.o -IC:/lua/include luapgsql.c -IC:/pgsql/include luapgsql.c: In function 'get_param': luapgsql.c:509:34: warning: implicit declaration of function 'htobe64' [-Wimplicit-function-declaration] (uint64_t )paramValues[n] = htobe64(swap.i); ^~~ mingw32-gcc -shared -o pgsql.dll luapgsql.o -LC:/pgsql/lib -lpq C:/lua/lua53.dll -lm C:/pgsql/lib/libpq.dll: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module pgsql.dll My system

Windows 10 MinGW (installed in C:\MinGW) Lua 5.3 (installed in C:\lua) LuaRocks 2.4.3 (installed in C:\LuaRocks) PostgreSQL 9.6.5 (installed in C:\pgsql incl. include files in C:\pgsql\include) What am I missing?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

daurnimator commented 6 years ago

See my comment here: https://github.com/arcapos/luapgsql/issues/7#issuecomment-74405324 re: windows support.

mrkskwsnck commented 6 years ago

Aww, snap :-(

mbalmer commented 6 years ago

Am 06.10.2017 um 10:11 schrieb Markus Kwaśnicki notifications@github.com:

Aww, snap :-(

Well, if you provide a patch, we can of course apply that, we just don’t have any windows development systems and hence can not test anything on that platform.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

daurnimator commented 6 years ago

As asprintf is no longer used in the current git HEAD, I expect you might have quite an easy time making it work on windows...

mrkskwsnck commented 6 years ago

It seems that I got rid of the first problem: I stupidly mixed up architectures. LuaRocks comes as 32 bit binaries for Windows just like MinGW does. But PostgreSQL's shared objects and include files were 64 bit.

Now after I switched to 32 bit (MinGW, Lua, LuaRocks and PostgreSQL), the error message File format not recognized disappeared. Unfortunately it still does not compile due to an undefined reference.

C:\> luarocks install --local luapgsql PQ_DIR=C:/pgsql PQ_INCDIR=C:/pgsql/include
Installing https://luarocks.org/luapgsql-1.6.1-1.rockspec
mingw32-gcc -O2 -c -o luapgsql.o -IC:/lua/include luapgsql.c -IC:/pgsql/include
luapgsql.c: In function 'get_param':
luapgsql.c:509:34: warning: implicit declaration of function 'htobe64' [-Wimplicit-function-declaration]
    *(uint64_t *)paramValues[n] = htobe64(swap.i);
                                  ^~~~~~~
mingw32-gcc -shared -o pgsql.dll luapgsql.o -LC:/pgsql/lib -lpq C:/lua/lua53.dll -lm
luapgsql.o:luapgsql.c:(.text+0x2904): undefined reference to `htobe64'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module pgsql.dll

Well, maybe I will take some time to look over that C code...

mbalmer commented 6 years ago

Am 06.10.2017 um 14:40 schrieb Markus Kwaśnicki notifications@github.com:

It seems that I got rid of the first problem: I stupidly mixed up architectures. LuaRocks comes as 32 bit binaries for Windows just like MinGW does. But PostgreSQL's shared objects and include files were 64 bit.

Now after I switched to 32 bit (MinGW, Lua, LuaRocks and PostgreSQL), the error message File format not recognized disappeared. Unfortunately it still does not compile due to an undefined reference.

C:> luarocks install --local luapgsql PQ_DIR=C:/pgsql PQ_INCDIR=C:/pgsql/include Installing https://luarocks.org/luapgsql-1.6.1-1.rockspec mingw32-gcc -O2 -c -o luapgsql.o -IC:/lua/include luapgsql.c -IC:/pgsql/include luapgsql.c: In function 'get_param': luapgsql.c:509:34: warning: implicit declaration of function 'htobe64' [-Wimplicit-function-declaration] (uint64_t )paramValues[n] = htobe64(swap.i); ^~~ mingw32-gcc -shared -o pgsql.dll luapgsql.o -LC:/pgsql/lib -lpq C:/lua/lua53.dll -lm luapgsql.o:luapgsql.c:(.text+0x2904): undefined reference to `htobe64' collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module pgsql.dll

Well, maybe I will take some time to look over that C code…

I suggest you „steal“ a htobe64() implementation from e.g. NetBSD (the licnese does allow you to include it in your program)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

mbalmer commented 6 years ago

Am 06.10.2017 um 14:47 schrieb Marc Balmer marc@msys.ch:

Am 06.10.2017 um 14:40 schrieb Markus Kwaśnicki notifications@github.com:

It seems that I got rid of the first problem: I stupidly mixed up architectures. LuaRocks comes as 32 bit binaries for Windows just like MinGW does. But PostgreSQL's shared objects and include files were 64 bit.

Now after I switched to 32 bit (MinGW, Lua, LuaRocks and PostgreSQL), the error message File format not recognized disappeared. Unfortunately it still does not compile due to an undefined reference.

C:> luarocks install --local luapgsql PQ_DIR=C:/pgsql PQ_INCDIR=C:/pgsql/include Installing https://luarocks.org/luapgsql-1.6.1-1.rockspec mingw32-gcc -O2 -c -o luapgsql.o -IC:/lua/include luapgsql.c -IC:/pgsql/include luapgsql.c: In function 'get_param': luapgsql.c:509:34: warning: implicit declaration of function 'htobe64' [-Wimplicit-function-declaration] (uint64_t )paramValues[n] = htobe64(swap.i); ^~~ mingw32-gcc -shared -o pgsql.dll luapgsql.o -LC:/pgsql/lib -lpq C:/lua/lua53.dll -lm luapgsql.o:luapgsql.c:(.text+0x2904): undefined reference to `htobe64' collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module pgsql.dll

Well, maybe I will take some time to look over that C code…

I suggest you „steal“ a htobe64() implementation from e.g. NetBSD (the licnese does allow you to include it in your program)

Here is a starting point: https://nxr.netbsd.org/search?q=htobe64&project=src&defs=&refs=&path=&hist=

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

mbalmer commented 6 years ago

Am 06.10.2017 um 10:11 schrieb Markus Kwaśnicki notifications@github.com:

Closed #47.

Did you get it up and running?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

mrkskwsnck commented 6 years ago

Not yet, but I will give it a try or two.

mrkskwsnck commented 6 years ago

I managed to compile luapgsql and link it to pgsql.dll succesfully on the MinGW32 platform. Now I would like to test it before I publish my changes. Can you give me an advice how I install that DLL file so I can run the provided test Lua scripts?

mbalmer commented 6 years ago

Am 10.10.2017 um 08:08 schrieb Markus Kwaśnicki notifications@github.com:

I managed to compile luapgsql and link it to pgsql.dll succesfully on the MinGW32 platform. Now I would like to test it before I publush my changes. Can you give me an advice how I install that DLL file so I can run the provided test Lua scripts?

Great news. You must put the DLL in a place where Lua can pick it up, I’d suggest C:\system\windows32, but I am not 100% sure if that is correct.

mrkskwsnck commented 6 years ago

Now I placed the pgsql.dll file within the package.cpath and/or package.path paths. When I try to require the pgsql module, it says the module cannot be found within the pgsql.dll file. Any ideas what is wrong?

> require "pgsql"
error loading module 'pgsql' from file '.\pgsql.dll':
        Das angegebene Modul wurde nicht gefunden.

stack traceback:
        [C]: in ?
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: in ?

BTW: Where can I get a look at the rockspec file for LuaRocks?

kiug commented 6 years ago

Hi, pgsql.dll is dynamically linked with libpq.dll.

libpq.dll is dynamically linked with: ssleay32.dll, libeay32.dll, libintl-8.dll.

libintl-8.dll is dynamically linked with: libiconv-2.dll.

All dll files must be placed in the same directory (within the package.cpath) or directory that is added to the PATH environment variable.

mbalmer commented 6 years ago

Am 10.10.2017 um 15:48 schrieb Markus Kwaśnicki notifications@github.com:

Now I placed the pgsql.dll file within the package.cpath and/or package.path paths. When I try to require the pgsql module, it says the module cannot be found within the pgsql.dll file. Any ideas what is wrong?

require "pgsql" error loading module 'pgsql' from file '.\pgsql.dll': Das angegebene Modul wurde nicht gefunden.

stack traceback: [C]: in ? [C]: in function 'require' stdin:1: in main chunk [C]: in ? BTW: Where can I get a look at the rockspec file for LuaRocks?

See github.com/arcapos/rockspecs http://github.com/arcapos/rockspecs for these.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/arcapos/luapgsql/issues/47#issuecomment-335478103, or mute the thread https://github.com/notifications/unsubscribe-auth/AAaAHyoVhayNwuiwgtcJ9wY3khmvlqKqks5sq3WogaJpZM4PvFr1.

mrkskwsnck commented 6 years ago

@kiug Thanks for your hint. Unfortunately, it still does not work to require the module. Although, all the DLL files you mentioned (libpq.dll, ssleay32.dll, libeay32.dll, libintl-8.dll, libiconv-2.dll) are located within LUA_CPATH. I put them all into the C:\lib\lua\5.3\?.dll folder.

> require "pgsql"
error loading module 'pgsql' from file 'C:\lua\..\lib\lua\5.3\pgsql.dll':
        Das angegebene Modul wurde nicht gefunden.

stack traceback:
        [C]: in ?
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: in ?
kiug commented 6 years ago

Check dependency of dll with Dependency Walker (http://www.dependencywalker.com).

mrkskwsnck commented 6 years ago

Good news, everyone! I successfully got pgsql.dll running. Also both tests (testdb.lua and testnumbers.lua) have passed.

@kiug Thanks for the Dependency Walker, which I didn't know until now. It turned out, that I again mixed up some 32 and 64 DLL files, as several of them are installed in my system. Also the dependencies (DLL files) need to be found in the system PATH and not LUA_CPATH.

I will fork this repository and provide a patch for Windows, soon.

mrkskwsnck commented 6 years ago

I created the pull request https://github.com/arcapos/luapgsql/pull/48

javacty commented 4 years ago

@mrkskwsnck I use your modify code (https://github.com/mrkskwsnck/luapgsql), compile in vc++ 2008 commond prompt, get errors: ...... luapgsql.obj : error LNK2019: unresolved external symbol PQconnectStart referenc ed in function pgsql_connectStart luapgsql.obj : error LNK2019: unresolved external symbol PQconnectPoll reference d in function pgsql_connectPoll luapgsql.obj : error LNK2019: unresolved external symbol luaL_argerror reference d in function pgsql_conn luapgsql.obj : error LNK2019: unresolved external symbol PQlibVersion referenced in function pgsql_libVersion luapgsql.obj : error LNK2019: unresolved external symbol PQping referenced in fu nction pgsql_ping luapgsql.obj : error LNK2019: unresolved external symbol lua_pushstring referenc ed in function pgsql_encryptPassword luapgsql.obj : error LNK2019: unresolved external symbol PQencryptPassword refer enced in function pgsql_encryptPassword luapgsql.obj : error LNK2019: unresolved external symbol PQunescapeBytea referen ced in function pgsql_unescapeBytea ...... win7 64bit LuaJIT-2.1.0-beta3 Visual C++ 2008 64

What can I do ? Thanks!

mrkskwsnck commented 4 years ago

@javacty It has been a while, since I was compiling on the Windows platform. I don't have much experience with MSVC compilers, as I prefer to work with GCC. Also I entirely switched to GNU/Linux.

Regarding your compiler errors, my first guess is, that you somehow forgot to either link a shared library (a.k.a. BLOB (Binary Large Object)) file or the compiler could not find the necessary header (include) files.

Anyway, I kept these personal notes, when I was compiling with Microsoft software back then. But I never used the GUI, so these are the command line compiling steps, which worked for me.

REM Try to install via luarocks and choose a compiler
luarocks install --local luapgsql PQ_DIR=C:\opt\pgsql PQ_INCDIR=C:\opt\pgsql\include

REM MW
mingw32-gcc -O2 -c -o luapgsql.o -IC:/opt/lua/include luapgsql.c -IC:/opt/pgsql/include
mingw32-gcc -shared -o pgsql.dll luapgsql.o -LC:/opt/pgsql/lib -lpq C:/opt/lua/lua53.dll -lm

REM MSVC
cl /nologo /MD /O2 -c -Foluapgsql.obj -IC:/opt/lua/include luapgsql.c -IC:\opt\pgsql\include
link -dll -def:pgsql.def -out:pgsql.dll C:/opt/lua/lua53.lib luapgsql.obj -libpath:C:\opt\pgsql/lib pq.lib

link -dll -out:pgsql.dll C:/opt/lua/lua53.lib luapgsql.obj -libpath:C:/opt/pgsql/lib libpq.lib -nodefaultlib:libcmt.lib

Good luck

pnm03 commented 3 months ago

you can get the file here, maybe it was corrupted at the root of the file. /www.dll-files.com