Menu

#935 2.5.1.1 fails to build on OS X

closed-fixed
None
5
2015-02-04
2013-02-18
No

Hello, I'm a manager of the MacPorts project, trying to update libgphoto2 at a user's request. But 2.5.1 and 2.5.1.1 do not build for me on OS X 10.8.2 Mountain Lion with Xcode 4.6. There are numerous warnings:

:info:build gphoto2-port-info-list.c:270:38: warning: implicitly declaring library function 'strdup' with type 'char *(const char *)'
:info:build                         list->info[j]->library_filename = strdup (filename);
:info:build                                                           ^
:info:build gphoto2-port-info-list.c:270:38: note: please include the header <string.h> or explicitly provide a declaration for 'strdup'
:info:build serial/unix.c:362:3: warning: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)'
:info:build                 snprintf (xname, 100, _("Serial Port %i"), x);
:info:build                 ^
:info:build serial/unix.c:362:3: note: please include the header <stdio.h> or explicitly provide a declaration for 'snprintf'
:info:build usbdiskdirect/linux.c:153:9: warning: implicit declaration of function 'readlink' is invalid in C99 [-Wimplicit-function-declaration]
:info:build                 ret = readlink (path, buf, PATH_MAX);
:info:build                       ^

Finally the build fails with:

:info:build usbscsi/linux.c:87:6: warning: implicit declaration of function 'flock' is invalid in C99 [-Wimplicit-function-declaration]
:info:build         if (flock(port->pl->fd, LOCK_EX | LOCK_NB) != 0) {
:info:build             ^
:info:build usbscsi/linux.c:87:26: error: use of undeclared identifier 'LOCK_EX'
:info:build         if (flock(port->pl->fd, LOCK_EX | LOCK_NB) != 0) {
:info:build                                 ^
:info:build usbscsi/linux.c:87:36: error: use of undeclared identifier 'LOCK_NB'
:info:build         if (flock(port->pl->fd, LOCK_EX | LOCK_NB) != 0) {
:info:build                                           ^
:info:build usbscsi/linux.c:108:26: error: use of undeclared identifier 'LOCK_UN'
:info:build         if (flock(port->pl->fd, LOCK_UN) != 0) {
:info:build                                 ^

libgphoto2 2.5.0 builds fine.

2 Attachments

Discussion

1 2 > >> (Page 1 of 2)
  • Marcus Meissner

    Marcus Meissner - 2013-02-18

    2 different issues:

    IMplicit strdup() ... This is weird, as gphoto2-port-info-list.c only received a a single line change between 2.5.0 and 2.5.1.1 and it was not in the headers section.
    it does include <string.h> ... so I would suspect a xcode problem here.

    what is probably a real issue introduced by 2.5.1.1 though:

    flock needs autoconf check, it might be missing on MacOSX

    does MacOSX support flock at all? what does the manpage say what headers need to be added?

     
  • Ryan Carsten Schmidt

    From the flock manpage, I think you just need to #include <sys/file.h> but I see you already do that in libgphoto2_port/usbscsi/linux.c on line 33.

    Current Xcode versions use the clang compiler (Xcode 4.6 uses "Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)") which is much more verbose about problems than GCC was. You should probably take its warning seriously.

     
  • Hubert Figuière

    Patch welcome. You have the system, you build from source. This bug would get fixed quick with a patch attached.

     
  • Marcus Meissner

    Marcus Meissner - 2013-02-19

    I take warnings seriously, but they should not be happening at all, as the file includes <string.h> (and also gcc definitely does not warn in my build) :/

    Same for flock and #include <sys file.h=""> :/

    So frankly, there is something weird happening during your xcode build somehow.

    does libgphoto2 2.5.0 really build within the same xcode environment without those errors?

     
  • Ryan Carsten Schmidt

    Yes, clang warns about things that gcc did not warn about; often, we've found that the things clang warns about are real problems that had previously gone unnoticed.

    I am not using the Xcode application or the xcodebuild command line program; I merely wanted to let you know that the versions of compilers I'm using are those that were installed by the Xcode 4.6 package.

    Yes, libgphoto2 2.5.0 really does build fine on the same system; libgphoto2 2.5.0 did not contain the flock code that is causing the errors I'm now experiencing.

    I don't know if I can provide a patch to fix this. C programming is not what I usually do; I usually just create packages for other developers' already-written code.

     
  • Marcus Meissner

    Marcus Meissner - 2013-02-19

    I just applied this patch to have a autoconf check for sys/file.h and flock() presence.

     
  • Marcus Meissner

    Marcus Meissner - 2013-02-19
     
  • Ryan Carsten Schmidt

    With that patch, the errors and warnings remain. The configure script output confirms:

    checking for flock... yes
    
     
  • Ryan Carsten Schmidt

    I have tested compiling with gcc 4.7.2 (as installed by MacPorts) and the situation is the same, so it's not a compiler-specific issue.

    In /usr/include/sys/fcntl.h (which is included from /usr/include/sys/file.h) the flock operation constants LOCK_SH, LOCK_EX, LOCK_NB and LOCK_UN, as well as the flock function itself and some other things, are defined inside the following conditional:

    #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
    

    So I suspect that condition is not being met. Recall previous mentions of these defines in [#722]. As explained in the Apple developer document linked from there, if you define _POSIX_C_SOURCE (which libgphoto2_port/gphoto2/gphoto2-port-portability.h does) then only SUSv3 functions are available; I guess flock is not SUSv3. If you also define _DARWIN_C_SOURCE, then extensions to the standard are also available, which I guess includes flock.

     

    Related

    Bugs: #722

  • Ryan Carsten Schmidt

    Adding -D_DARWIN_C_SOURCE to CPPFLAGS does allow libgphoto2 2.5.1.1 to build.

     
  • Marcus Meissner

    Marcus Meissner - 2013-02-19

    AH, I understand the core problem now.

    Default Linux builds are more relaxed in their standard compliance.

    To achieve what your build is doing we need to add "-ansi" ... then I also see
    start seeing some of your issues.

     
  • Marcus Meissner

    Marcus Meissner - 2013-02-24

    I now tagged the files needing _BSD_SOURCE or _POSIX_C_SOURCE accordingly, so next round it should be better. (in SVN trunk, will be in 2.5.2)

     
  • Marcus Meissner

    Marcus Meissner - 2013-02-24
    • status: open --> pending-fixed
     
  • Marcus Meissner

    Marcus Meissner - 2013-05-12
    • status: pending-fixed --> closed-fixed
     
  • Marcus Meissner

    Marcus Meissner - 2013-05-12

    fixed in 2.5.2

     
  • Bill Waggoner

    Bill Waggoner - 2013-06-16

    Building on OSX 10.8.4 in version 2.5.2:

    ~~~~~~~~~
    --> gphoto2 -v
    gphoto2 2.5.2.1

    Copyright (c) 2000-2013 Lutz Mueller and others

    gphoto2 comes with NO WARRANTY, to the extent permitted by law. You may
    redistribute copies of gphoto2 under the terms of the GNU General Public
    License. For more information about these matters, see the files named COPYING.

    This version of gphoto2 is using the following software versions and options:
    gphoto2 2.5.2.1 gcc, popt(m), no exif, no cdk, no aa, no jpeg, readline
    libgphoto2 2.5.2.1 all camlibs, gcc, ltdl, no EXIF
    libgphoto2_port 0.10.0 gcc, ltdl, USB, serial without locking
    ~~~~~~~

    Does not seem to fix the problem. I needed to use

    make CPPFLAGS=-D_DARWIN_C_SOURCE

    to build libgphoto2

     
  • Marcus Meissner

    Marcus Meissner - 2013-06-16

    can you post the current errors/warnings?

     
  • Marcus Meissner

    Marcus Meissner - 2013-06-16
    • status: closed-fixed --> open
     
  • Misty De Meo

    Misty De Meo - 2013-06-26

    I'm having the same issue as the original reporter building libgphoto2 2.5.2 on Mac OS X 10.4.11. I was able to build 2.5.1 using the reporter's patch. I'm also able to build 2.5.2 on newer Mac OS versions with -D_DARWIN_C_SOURCE in the flags.

    My build logs (including config.log) are here: https://gist.github.com/5869573 As you can see, configure found sys/file.h and flock.

     
  • Marcus Meissner

    Marcus Meissner - 2013-06-30

    there might be constant defines for flock missing, i have added them.

    nethertheless, flock is still implicitly defined here, which is strange :/

    can you attach the sys/file.h that is used, to check what define we actually need ., as I do not have access to a Xcode SDK environment (probably should try to ask my friends if someone has that)

     
  • Ryan Carsten Schmidt

    /usr/include/sys/file.h on OS X 10.8.4

     
  • Ryan Carsten Schmidt

    /usr/include/sys/fcntl.h on OS X 10.8.4

     
  • Misty De Meo

    Misty De Meo - 2013-07-01

    /usr/include/sys/file.h from 10.4.11

     
  • Misty De Meo

    Misty De Meo - 2013-07-01

    /usr/include/sys/fcntl.h from 10.4.11

     
  • Marcus Meissner

    Marcus Meissner - 2014-08-17
     
1 2 > >> (Page 1 of 2)

Log in to post a comment.