Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difficulty building on aix - cannot locate struct timeval #46

Closed
slestak opened this issue Jun 15, 2011 · 24 comments
Closed

difficulty building on aix - cannot locate struct timeval #46

slestak opened this issue Jun 15, 2011 · 24 comments

Comments

@slestak
Copy link

slestak commented Jun 15, 2011

receive the following message:

In file included from hiredis/hiredis.c:39:
hiredis/hiredis.h:175: warning: 'struct timeval' declared inside parameter list
hiredis/hiredis.h:175: warning: its scope is only this definition or declaration, which is probably not what you want

I am using gcc 4.4 on aix 5.3.

@pietern
Copy link
Contributor

pietern commented Jun 15, 2011

That's pretty weird... This AIX documentation page states that sys/time.h should define the struct, and that file is included from hiredis.h. Can you check where the struct is defined on your system? Thanks.

@slestak
Copy link
Author

slestak commented Jun 15, 2011

I have time.h at:

/usr/include/sys/time.h
/usr/include/time.h

@pietern
Copy link
Contributor

pietern commented Jun 15, 2011

Since sys/time.h is already included by hiredis.h, it would be helpful to know where struct timeval is defined. Could you do a grep or something in /usr/include to find out? I don't have access to an AIX machine, so I'll need your help in fixing this :-)

@slestak
Copy link
Author

slestak commented Jun 15, 2011

Tried adjusting the include search dirs in Makefile with no joy.

@slestak
Copy link
Author

slestak commented Jun 15, 2011

Looks like /usr/include/sys/time.h is what we want.

/usr/include/sys/time.h:
   91 : struct timeval {
  103 : struct timeval32 {
  113 : struct timeval64 {
  159 : extern int gettimeofday(struct timeval *__restrict__, void *__restrict__);
  161 : extern int settimeofday(struct timeval *, struct timezone *);
  163 : extern int utimes(const char *, const struct timeval *);
  222 :             fd_set *__restrict__, struct timeval *__restrict__);
  227 :         struct timeval *__restrict__ __timeout)  
  233 : extern int select(int, fd_set *__restrict__, fd_set *__restrict__, fd_set *__restrict__, struct timeval *__restrict__);
  237 : extern int __fd_select(uint, void *, void *, void *, struct timeval *);
  239 :         void *__exceptlist, struct timeval *__timeout)
  245 : extern  int select(uint, void *, void *, void *, struct timeval *);
  511 :  * struct timeval {

@slestak
Copy link
Author

slestak commented Jun 15, 2011

BTW, ty for looking at this.

@pietern
Copy link
Contributor

pietern commented Jun 15, 2011

No problem. Did you try adding the include path argument -I/usr/include to the compiler task in the Makefile (just to be sure /usr/include is in the default compiler path)? Otherwise: could you post your sys/time.h as a gist? There might be some #ifdef's in there that prevent the struct from actually being defined. Thanks!

@slestak slestak closed this as completed Jun 15, 2011
@slestak slestak reopened this Jun 15, 2011
@slestak
Copy link
Author

slestak commented Jun 15, 2011

Woops, didnt mean to close issue.

Here is the gist

https://gist.github.com/1027378

@slestak
Copy link
Author

slestak commented Jun 15, 2011

yes, I have tried adjusting CFLAGS in the Makefile.

CFLAGS=-O3 -Wall -Wextra -I. -Ijansson/src -Ihttp-parser -I/usr/include

@pietern
Copy link
Contributor

pietern commented Jun 15, 2011

Thanks for the header file. This is a problem with feature test macro's, confusing stuff. Judging from the links below (look for _XOPEN_SOURCE) removing the #ifdef __linux__ block in fmacros.h and always setting _XOPEN_SOURCE to 700 would fix this issue. If I'm correct, this value enables _XOPEN_SOURCE_EXTENDED, which is the condition for the prototypes in sys/time.h to be included. Can you verify if this trick works?

[1] http://www.gnu.org/s/hello/manual/libc/Feature-Test-Macros.html
[2] http://www.kernel.org/doc/man-pages/online/pages/man7/feature_test_macros.7.html

@slestak
Copy link
Author

slestak commented Jun 15, 2011

I edited the header as so

https://gist.github.com/1027739

did not get any further.

@pietern
Copy link
Contributor

pietern commented Jun 15, 2011

Another thing we could try is removing _XOPEN_SOURCE altogether. According to very old documentation this should make the compiler use defaults which could work. Another thing could be defining _XOPEN_SOURCE_EXTENDED in fmacros.h (either just defining it, or bluntly defining it as 1). While you're at it, could you check if __aix__ gets defined? When we find out which features macro's should be defined on AIX, we only need a platform macro to enable them from the generic header file.

@slestak
Copy link
Author

slestak commented Jun 15, 2011

How can I see if aix is set? I apologize. i am not a c dev. Are you on freenode?

@pietern
Copy link
Contributor

pietern commented Jun 15, 2011

Yes, #redis.

@slestak
Copy link
Author

slestak commented Jun 15, 2011

Pls leave this open a few days and I will submit a pull request with the aix changes we discussed.

@slestak
Copy link
Author

slestak commented Jul 8, 2011

doh, I had a week of vacation and never followed up on this. Trying to pick up where we left off.

@daelious
Copy link

I'm having this issue in the new 2.4 release, has anyone else been looking into this?

@pietern
Copy link
Contributor

pietern commented Oct 14, 2011

@dealious: I'm sorrry, this issue appears to have gotten a bit silent. You are trying to build on AIX, correct?

@slestak
Copy link
Author

slestak commented Oct 14, 2011

I'm sorry Peter. I was supposed to work on this but to push my
project forward I had to move my celery instance to RabbitMQ.

@daelious
Copy link

@pietern Yes I am trying to build on AIX 5.2 (preferably using xlc as the compiler, though for testing gcc is acceptable).

@ooXavier
Copy link

Removing _XOPEN_SOURCE did the trick for me on AIX 5.3 with gcc 4.6.1
But I ended with an other error : net.c:256:34: error: 'AF_LOCAL' undeclared (first use in this function) so i added a define for AF_UNIX.

#ifndef __HIREDIS_FMACRO_H
#define __HIREDIS_FMACRO_H

#if !defined(_BSD_SOURCE)
#define _BSD_SOURCE
#endif

#if defined(__sun__)
#define _POSIX_C_SOURCE 200112L
#elif defined(__linux__)
#define _XOPEN_SOURCE 600
#elif defined(__AIX) || defined(_AIX)

#ifndef AF_LOCAL
#define AF_LOCAL AF_UNIX
#endif

#else
#define _XOPEN_SOURCE
#endif

#endif

You can also add this in deps/linenoise/Makefile and src/Makefile for AIX :

# Fallback to gcc when $CC is not in $PATH.
CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')

But I stil got a ton of errors after while compiling Redis (eg. anet.c gives vsnprintf not declared, .....).

@slestak
Copy link
Author

slestak commented Apr 16, 2012

interesting. The pure python bindings meet my need and my gcc is broken at the moment so I am not pursuing this matter anymore myself.

@pietern
Copy link
Contributor

pietern commented Jul 11, 2013

This will be hard to do without a way to verify if it works or not.

I hope that if there is somebody with an AIX box who tries to use hiredis, he or she will open a new issue.

Closing this one.

@pietern pietern closed this as completed Jul 11, 2013
@tw-bert
Copy link

tw-bert commented Jun 19, 2014

EDIT We did some extra unneeded customizations, I removed them. Below is only what's needed.

Building hiredis 0.1.3 on AIX7.1 x64, I just ran into the same problems.
Solved by:

  1. _XOPEN_SOURCE 700 in fmacros.h
  2. #define AF_LOCAL AF_UNIX in net.h (not only for sun)

After this, don't start with python setup.py build_ext, but simply do python setup.py build (there is a build step that prepares a lib for build_ext).

We also have some general gcc tuning, but that's not related to this issue.
He're the full linking command (compile phase succeeds now, warnings, but no errors)
gcc -DNDEBUG -g -fwrapv -O3 -W1 -Wstrict-prototypes -maix64 -ffast-math -D_AIX -D_AIX53 -D_AIX61 -D_AIX71 -I/opt/freeware/include -I/usr/include -Ivendor/hiredis -c vendor/hiredis/sds.c -o build/temp.aix-7.1-2.7/vendor/hiredis/sds.o ar -X64 rc build/temp.aix-7.1-2.7/libhiredis.a build/temp.aix-7.1-2.7/vendor/hiredis/hiredis.o build/temp.aix-7.1-2.7/vendor/hiredis/net.o build/temp.aix-7.1-2.7/vendor/hiredis/sds.o

result in redis-py/hiredis-py:

ipython --classic --no-banner
>>> import hiredis
>>> hiredis.__version__
'0.1.3'
>>> import redis
>>> redis.utils.HIREDIS_AVAILABLE
True
>>> redis.VERSION
(2, 10, 1)
>>> exit()

Resulting dependencies:

ldd hiredis.so
hiredis.so needs:
     /usr/lib/libc.a(shr_64.o)
     /unix
     /usr/lib/libcrypt.a(shr_64.o)

Could help someone, cheers TW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants