cygwin编译下,ffi无法调用nginx的函数

414 views
Skip to first unread message

Heero Zhang

unread,
Nov 26, 2013, 7:16:34 AM11/26/13
to open...@googlegroups.com
使用cygwin在windows下编译了1.4.3.3版本的openresty,使用时发现ffi调用openssl的函数都可以,比如resty.random.bytes
但是nginx的函数就不行了,string库中32行C.ngx_hex_dump(buf, s, #s)报如下错误

2013/11/26 17:48:25 [error] 12724#0: *7 lua entry thread aborted: runtime error:
 /usr/local/openresty/lualib/resty/string.lua:32: No such file or directory
stack traceback:
coroutine 0:
        [C]: in function '__index'
        /usr/local/openresty/lualib/resty/string.lua:32: in function 'to_hex'

不知这得如何解决? 感谢。

Yichun Zhang (agentzh)

unread,
Nov 26, 2013, 2:38:23 PM11/26/13
to openresty
Hello!

2013/11/26 Heero Zhang:
> 使用cygwin在windows下编译了1.4.3.3版本的openresty,使用时发现ffi调用openssl的函数都可以,比如resty.random.bytes
> 但是nginx的函数就不行了,string库中32行C.ngx_hex_dump(buf, s, #s)报如下错误
>

貌似在 cygwin 上导出符号用的 -Wl,-E 链接器选择没有起作用。你能把你构造 openresty 时生成的
build/nginx-1.4.3/objs/autoconf.err 文件贴出来看么?

当然,“No such file or directory”这个错误信息也有些诡异。。。我手头没有 Cygwin 的环境,所以不容易帮你调试。

另外,请在你本地尝试下面这个最小化了的嵌入 LuaJIT 的 C 宿主程序(用来摸拟 nginx),将此文件保存为 test.c:

/* File test.c */
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>

int foo(void) {
return 32;
}

int main(void) {
lua_State *L;

L = luaL_newstate();
luaL_openlibs(L);

if (luaL_dostring(L, "local ffi = require 'ffi'\n"
"ffi.cdef[[int foo(void);]]\n"
"print('foo() returned', ffi.C.foo())")
!= 0)
{
fprintf(stderr, "failed to load and run Lua code: %s\n",
lua_tostring(L, -1));
}

lua_close(L);
return 0;
}

然后使用下面的 shell 命令进行编译:

LUAJIT_LIB=/usr/local/openresty/luajit/lib
LUAJIT_INC=/usr/local/openresty/luajit/include/luajit-2.0

gcc -Wl,-E -I$LUAJIT_INC -O2 -Wl,-rpath,$LUAJIT_LIB -o test -ldl
-lm -L$LUAJIT_LIB -lluajit-5.1 test.c

完事了,再执行生成的 ./test 可执行文件:

./test

期望的输出是

foo() returned 32

Regards,
-agentzh

Heero Zhang

unread,
Nov 26, 2013, 4:09:18 PM11/26/13
to open...@googlegroups.com
果然如春哥所想的一样是-E的问题,编译提示这个:
$ ./build.sh
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: warning: --export-dynamic is not supported for PE targets, did you mean --export-all-symbols?

这时候运行测试./test返回的就是No such file or directory
把-E改成--export-all-symbols就正常了

尝试手动把objs/nginx: objs/src/core/nginx.o下的-E改成了--export-all-symbols,重新编译后,nginx跑resty.string库也一切正常。

这么改是否有其他问题还不得知,Windows主要用于本机开发,功能正常就满足了。

感谢春哥!





--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

Heero Zhang

unread,
Nov 26, 2013, 4:12:16 PM11/26/13
to open...@googlegroups.com
autoconf.err文件内容如下,能看到checking for export symbols by default这里有提示


----------------------------------------
checking for C compiler


----------------------------------------
checking for gcc -pipe switch


----------------------------------------
checking for --with-ld-opt="-Wl,-rpath,/usr/local/openresty/luajit/lib"


----------------------------------------
checking for gcc builtin atomic operations


----------------------------------------
checking for C99 variadic macros


----------------------------------------
checking for gcc variadic macros


----------------------------------------
checking for unistd.h


----------------------------------------
checking for inttypes.h


----------------------------------------
checking for limits.h


----------------------------------------
checking for sys/filio.h

objs/autotest.c:3:23: fatal error: sys/filio.h: No such file or directory
 #include <sys/filio.h>
                       ^
compilation terminated.
----------


#include <sys/filio.h>

int main() {
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c
----------

----------------------------------------
checking for sys/param.h


----------------------------------------
checking for sys/mount.h


----------------------------------------
checking for sys/statvfs.h


----------------------------------------
checking for crypt.h


----------------------------------------
checking for poll()


----------------------------------------
checking for /dev/poll

objs/autotest.c:4:25: fatal error: sys/devpoll.h: No such file or directory
 #include <sys/devpoll.h>
                         ^
compilation terminated.
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/devpoll.h>

int main() {
    int  n, dp; struct dvpoll  dvp;
                  dp = 0;
                  dvp.dp_fds = NULL;
                  dvp.dp_nfds = 0;
                  dvp.dp_timeout = 0;
                  n = ioctl(dp, DP_POLL, &dvp);
                  if (n == -1) return 1;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for kqueue

objs/autotest.c:4:23: fatal error: sys/event.h: No such file or directory
 #include <sys/event.h>
                       ^
compilation terminated.
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/event.h>

int main() {
    int kq; kq = kqueue();
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for crypt()

/tmp/ccflWOeh.o:autotest.c:(.text+0x1e): undefined reference to `crypt'
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>


int main() {
    crypt("test", "salt");;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for crypt() in libcrypt


----------------------------------------
checking for F_READAHEAD

objs/autotest.c: In function 'main':
objs/autotest.c:7:14: error: 'F_READAHEAD' undeclared (first use in this function)
     fcntl(0, F_READAHEAD, 1);;
              ^
objs/autotest.c:7:14: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
    fcntl(0, F_READAHEAD, 1);;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for posix_fadvise()


----------------------------------------
checking for O_DIRECT


----------------------------------------
checking for F_NOCACHE

objs/autotest.c: In function 'main':
objs/autotest.c:7:14: error: 'F_NOCACHE' undeclared (first use in this function)
     fcntl(0, F_NOCACHE, 1);;
              ^
objs/autotest.c:7:14: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
    fcntl(0, F_NOCACHE, 1);;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for directio()

objs/autotest.c: In function 'main':
objs/autotest.c:8:17: error: 'DIRECTIO_ON' undeclared (first use in this function)
     directio(0, DIRECTIO_ON);;
                 ^
objs/autotest.c:8:17: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
                  #include <sys/fcntl.h>

int main() {
    directio(0, DIRECTIO_ON);;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for statfs()

objs/autotest.c: In function 'main':
objs/autotest.c:9:20: error: storage size of 'fs' isn't known
     struct statfs  fs;
                    ^
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/param.h>
                  #include <sys/mount.h>
                  

int main() {
    struct statfs  fs;
                  statfs(".", &fs);;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for statvfs()


----------------------------------------
checking for dlopen()


----------------------------------------
checking for sched_yield()


----------------------------------------
checking for SO_SETFIB

objs/autotest.c: In function 'main':
objs/autotest.c:7:31: error: 'SO_SETFIB' undeclared (first use in this function)
     setsockopt(0, SOL_SOCKET, SO_SETFIB, NULL, 4);
                               ^
objs/autotest.c:7:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>

int main() {
    setsockopt(0, SOL_SOCKET, SO_SETFIB, NULL, 4);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for SO_ACCEPTFILTER

objs/autotest.c: In function 'main':
objs/autotest.c:7:31: error: 'SO_ACCEPTFILTER' undeclared (first use in this function)
     setsockopt(0, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0);
                               ^
objs/autotest.c:7:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>

int main() {
    setsockopt(0, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for TCP_DEFER_ACCEPT

objs/autotest.c: In function 'main':
objs/autotest.c:9:32: error: 'TCP_DEFER_ACCEPT' undeclared (first use in this function)
     setsockopt(0, IPPROTO_TCP, TCP_DEFER_ACCEPT, NULL, 0);
                                ^
objs/autotest.c:9:32: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
                  #include <netinet/in.h>
                  #include <netinet/tcp.h>

int main() {
    setsockopt(0, IPPROTO_TCP, TCP_DEFER_ACCEPT, NULL, 0);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT

objs/autotest.c: In function 'main':
objs/autotest.c:9:32: error: 'TCP_KEEPIDLE' undeclared (first use in this function)
     setsockopt(0, IPPROTO_TCP, TCP_KEEPIDLE, NULL, 0);
                                ^
objs/autotest.c:9:32: note: each undeclared identifier is reported only once for each function it appears in
objs/autotest.c:10:46: error: 'TCP_KEEPINTVL' undeclared (first use in this function)
                   setsockopt(0, IPPROTO_TCP, TCP_KEEPINTVL, NULL, 0);
                                              ^
objs/autotest.c:11:46: error: 'TCP_KEEPCNT' undeclared (first use in this function)
                   setsockopt(0, IPPROTO_TCP, TCP_KEEPCNT, NULL, 0);
                                              ^
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
                  #include <netinet/in.h>
                  #include <netinet/tcp.h>

int main() {
    setsockopt(0, IPPROTO_TCP, TCP_KEEPIDLE, NULL, 0);
                  setsockopt(0, IPPROTO_TCP, TCP_KEEPINTVL, NULL, 0);
                  setsockopt(0, IPPROTO_TCP, TCP_KEEPCNT, NULL, 0);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for TCP_INFO

objs/autotest.c: In function 'main':
objs/autotest.c:9:31: error: invalid application of 'sizeof' to incomplete type 'struct tcp_info'
     socklen_t optlen = sizeof(struct tcp_info);
                               ^
objs/autotest.c:10:35: error: storage size of 'ti' isn't known
                   struct tcp_info ti;
                                   ^
objs/autotest.c:15:46: error: 'TCP_INFO' undeclared (first use in this function)
                   getsockopt(0, IPPROTO_TCP, TCP_INFO, &ti, &optlen);
                                              ^
objs/autotest.c:15:46: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
                  #include <netinet/in.h>
                  #include <netinet/tcp.h>

int main() {
    socklen_t optlen = sizeof(struct tcp_info);
                  struct tcp_info ti;
                  ti.tcpi_rtt = 0;
                  ti.tcpi_rttvar = 0;
                  ti.tcpi_snd_cwnd = 0;
                  ti.tcpi_rcv_space = 0;
                  getsockopt(0, IPPROTO_TCP, TCP_INFO, &ti, &optlen);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for accept4()


----------------------------------------
checking for int size


----------------------------------------
checking for long size


----------------------------------------
checking for long long size


----------------------------------------
checking for void * size


----------------------------------------
checking for uint64_t


----------------------------------------
checking for sig_atomic_t


----------------------------------------
checking for sig_atomic_t size


----------------------------------------
checking for socklen_t


----------------------------------------
checking for in_addr_t


----------------------------------------
checking for in_port_t


----------------------------------------
checking for rlim_t


checking for uintptr_t

checking for system byte ordering

----------------------------------------
checking for size_t size


----------------------------------------
checking for off_t size


----------------------------------------
checking for time_t size


----------------------------------------
checking for setproctitle()

/tmp/ccmEs23b.o:autotest.c:(.text+0x16): undefined reference to `setproctitle'
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int main() {
    setproctitle("test");;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for pread()


----------------------------------------
checking for pwrite()


----------------------------------------
checking for sys_nerr

144
----------------------------------------
checking for localtime_r()


----------------------------------------
checking for posix_memalign()


----------------------------------------
checking for memalign()


----------------------------------------
checking for mmap(MAP_ANON|MAP_SHARED)


----------------------------------------
checking for mmap("/dev/zero", MAP_SHARED)


----------------------------------------
checking for System V shared memory

objs/autotest.c: In function 'main':
objs/autotest.c:9:51: error: 'SHM_R' undeclared (first use in this function)
                   id = shmget(IPC_PRIVATE, 4096, (SHM_R|SHM_W|IPC_CREAT));
                                                   ^
objs/autotest.c:9:51: note: each undeclared identifier is reported only once for each function it appears in
objs/autotest.c:9:57: error: 'SHM_W' undeclared (first use in this function)
                   id = shmget(IPC_PRIVATE, 4096, (SHM_R|SHM_W|IPC_CREAT));
                                                         ^
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/ipc.h>
                  #include <sys/shm.h>

int main() {
    int  id;
                  id = shmget(IPC_PRIVATE, 4096, (SHM_R|SHM_W|IPC_CREAT));
                  if (id == -1) return 1;
                  shmctl(id, IPC_RMID, NULL);;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for POSIX semaphores


----------------------------------------
checking for struct msghdr.msg_control


----------------------------------------
checking for ioctl(FIONBIO)


----------------------------------------
checking for struct tm.tm_gmtoff

objs/autotest.c: In function 'main':
objs/autotest.c:8:22: error: 'struct tm' has no member named 'tm_gmtoff'
     struct tm  tm; tm.tm_gmtoff = 0;
                      ^
objs/autotest.c:9:40: error: 'struct tm' has no member named 'tm_gmtoff'
                   printf("%d", (int) tm.tm_gmtoff);
                                        ^
----------

#include <sys/types.h>
#include <unistd.h>
#include <time.h>
                  #include <stdio.h>

int main() {
    struct tm  tm; tm.tm_gmtoff = 0;
                  printf("%d", (int) tm.tm_gmtoff);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for struct dirent.d_namlen

objs/autotest.c: In function 'main':
objs/autotest.c:8:28: error: 'struct dirent' has no member named 'd_namlen'
     struct dirent  dir; dir.d_namlen = 0;
                            ^
objs/autotest.c:9:41: error: 'struct dirent' has no member named 'd_namlen'
                   printf("%d", (int) dir.d_namlen);
                                         ^
----------

#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
                  #include <stdio.h>

int main() {
    struct dirent  dir; dir.d_namlen = 0;
                  printf("%d", (int) dir.d_namlen);
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for struct dirent.d_type


----------------------------------------
checking for sysconf(_SC_NPROCESSORS_ONLN)


----------------------------------------
checking for openat(), fstatat()


----------------------------------------
checking for getaddrinfo()


----------------------------------------
checking for LuaJIT library in /home/hz/ngx_openresty-1.4.3.3/build/luajit-root/usr/local/openresty/luajit/lib and /home/hz/ngx_openresty-1.4.3.3/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.0 (specified by the LUAJIT_LIB and LUAJIT_INC env)


----------------------------------------
checking for export symbols by default

/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: warning: --export-dynamic is not supported for PE targets, did you mean --export-all-symbols?

----------------------------------------
checking for SO_PASSCRED

objs/autotest.c: In function 'main':
objs/autotest.c:8:31: error: 'SO_PASSCRED' undeclared (first use in this function)
     setsockopt(1, SOL_SOCKET, SO_PASSCRED, NULL, 0);;
                               ^
objs/autotest.c:8:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>

int main() {
    setsockopt(1, SOL_SOCKET, SO_PASSCRED, NULL, 0);;
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c -Wl,-rpath,/usr/local/openresty/luajit/lib
----------

----------------------------------------
checking for PCRE library


----------------------------------------
checking for PCRE JIT support


----------------------------------------
checking for OpenSSL library


----------------------------------------
checking for zlib library

Yichun Zhang (agentzh)

unread,
Nov 26, 2013, 4:29:34 PM11/26/13
to openresty
Hello!

2013/11/26 Heero Zhang:
> 果然如春哥所想的一样是-E的问题,编译提示这个:
[...]
> 这时候运行测试./test返回的就是No such file or directory。
> 把-E改成--export-all-symbols就正常了
>

多谢反馈!

我刚刚给 ngx_lua 模块准备了一个补丁,让它自动测试并启用 --export-all-symbols 这个链接器选项,你能在你那里测试一下吗?

具体步骤是

cd /path/to/ngx_openresty-1.4.3.3/bundle/ngx_lua-0.9.2/
wget http://openresty.org/download/ngx-lua-cygwin-export-symbols.patch
-O a.patch
patch -p1 < a.patch
cd ../..
./configure --with-luajit -j2
make -j2
make install

看看在你那里是否可以工作了。多谢!

Regards,
-agentzh

Heero Zhang

unread,
Nov 27, 2013, 1:04:42 AM11/27/13
to open...@googlegroups.com
应用了补丁,但没有走到检测"export symbols by default (--export-all-symbols)"的这一步。
在我这check -E并没有failed,这个问题似乎只是警告
checking for export symbols by default (-E) ... found
checking for SO_PASSCRED ... not found

autoconf.err如下
----------------------------------------
checking for export symbols by default (-E)

/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: warning: --export-dynamic is not supported for PE targets, did you mean --export-all-symbols?

----------------------------------------
checking for SO_PASSCRED




Regards,
-agentzh

Yichun Zhang (agentzh)

unread,
Nov 27, 2013, 2:16:31 AM11/27/13
to openresty
Hello!

2013/11/26 Heero Zhang:
> 应用了补丁,但没有走到检测"export symbols by default (--export-all-symbols)"的这一步。
> 在我这check -E并没有failed,这个问题似乎只是警告
> checking for export symbols by default (-E) ... found
> checking for SO_PASSCRED ... not found
>

多谢反馈!请在原有补丁的基础之上,再尝试下面这个补丁:

http://openresty.org/download/ngx-lua-cygwin-export-symbols-2.patch

多谢!

-agentzh

Heero Zhang

unread,
Nov 27, 2013, 4:13:52 AM11/27/13
to open...@googlegroups.com
已测试,能正常工作了,感谢春哥。

我下面记录了cygwin编译openresty需要改动的地方,能对你或其他人有帮助最好。

主要是在cygwin下,编译lua-cjson,rds, redis等库需要链接lua的lib,而luajit在cygwin下编译不会有.a文件(而是叫cyglua51.dll的文件),而链接dll的话有很多麻烦的地方,所以我改成了静态编译,主要方便。

修改根目录的configure文件
diff --git "a/configure" "b/configure"
index 945c47d..232a135 100644
--- "a/configure"
+++ "b/configure"
@@ -548,7 +548,11 @@ _END_
         if (defined $cc) {
             $extra_opts .= " CC='$cc'";
         }
-
+        
+        if ($OS eq 'cygwin') {
+            $extra_opts .= " BUILDMODE=static";
+        }
+        
         if (defined $cores) {
             shell "${make} -j$cores$extra_opts PREFIX=$luajit_prefix", $dry_run;
         } else {


修改lua-cjson文件
diff --git "a/ngx_openresty-1.4.3.3/bundle/lua-cjson-1.0.3/Makefile" "b/ngx_openresty-1.4.3.3/bundle/lua-cjson-1.0.3/Makefile"
index d34ff6d..916a6ba 100644
--- "a/ngx_openresty-1.4.3.3/bundle/lua-cjson-1.0.3/Makefile"
+++ "b/ngx_openresty-1.4.3.3/bundle/lua-cjson-1.0.3/Makefile"
@@ -12,6 +12,10 @@ LDFLAGS +=         -shared
 #PREFIX ?=          /opt/local
 #LDFLAGS +=         -bundle -undefined dynamic_lookup
 
+ifeq ($(OS),Windows_NT)
+  LDFLAGS2 += -L../luajit-root/usr/local/openresty/luajit -lluajit-5.1
+endif
 LUA_INCLUDE_DIR ?= $(PREFIX)/include
 LUA_LIB_DIR ?=     $(PREFIX)/lib/lua/$(LUA_VERSION)
 
@@ -29,7 +33,7 @@ INSTALL ?= install
 all: cjson.so
 
 cjson.so: lua_cjson.o strbuf.o
- $(CC) $(LDFLAGS) -o $@ $^
+ $(CC) $(LDFLAGS) -o $@ $^ $(LDFLAGS2)
 
 install:
  $(INSTALL) -d $(DESTDIR)/$(LUA_LIB_DIR)

其他lua-rds-parser和lua-redis-parser也是类似修改法








-agentzh

Yichun Zhang (agentzh)

unread,
Nov 27, 2013, 2:57:09 PM11/27/13
to openresty
Hello!

2013/11/27 Heero Zhang:
> 已测试,能正常工作了,感谢春哥。
>

好极。多谢反馈!

> 主要是在cygwin下,编译lua-cjson,rds,
> redis等库需要链接lua的lib,而luajit在cygwin下编译不会有.a文件(而是叫cyglua51.dll的文件),而链接dll的话有很多麻烦的地方,所以我改成了静态编译,主要方便。
>

不幸的是,你这里的做法是错误的(而且是常见的一种错误)。

Nginx 本身和你的每一个 Lua C 模块都会包含一个独立的 LuaJIT
库的副本,每个副本都完全不知道其他副本的存在。当这些副本在一个进程空间内的同一份 Lua
代码中混用时,会导致极难调试的问题(包括进程崩溃)。应当绝对避免这种用法。

Regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages