How to install luasql on Linux CentOS 7?

2019-08-01 09:49发布

问题:

I tried to install luasql on my Linux CentOS 7 computer with this command:

luarocks install luasql-postgres

but unfortunately I got the following error:

Installing https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luasql-postgres-2.3.5-2.rockspec...
Using https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/luasql-postgres-2.3.5-2.rockspec... switching to 'build' mode

Error: Could not find header file for PGSQL
  No file libpq-fe.h in /usr/local/include
  No file libpq-fe.h in /usr/include
You may have to install PGSQL in your system and/or pass PGSQL_DIR or PGSQL_INCDIR to the luarocks command.
Example: luarocks install luasql-postgres PGSQL_DIR=/usr/local

I tried then to run the last line luarocks install luasql-postgres PGSQL_DIR=/usr/local but I had no improvement...

What should I do?

回答1:

The Lua bits of this are fine; the error you're getting is that the C bits aren't there.

In general, when you are interfacing with a C library, you need to make sure you have the C library's -dev (for Debianish) or -devel (for Redhatish) package installed.

In your case, you can probably just do the following as root on your box:

yum install postgresql-devel

...and then attempt your luarocks install again.

Or, you could try the OS native package instead:

yum install lua-sql-postgresql

I personally prefer using the OS packages for stable Lua libs that don't change much, but it's your call...