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

Visual C++ Compatibility #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

qmfrederik
Copy link
Contributor

This pull request fixes incompatibilities between the Visual C++ compiler and the libusbmuxd codebase.

It consists of these changes:

  • In the public headers, the function definitions are now prefixed by USBMUXD_API_MSC. On the current codebase, Visual C++ generates a compiler C2375 because the function declarations in the public header and the source files differ. Recyling USBMUXD_API in the public headers doesn't work, because it value depends on what is defined in config.h, and that's specific to the libimobiledevice build, not what the user is building.
    Instead, a new define USBMUXD_API_MSC is used which adds the __declspec( dllexport ) prefix only if Visual C++ is used. USBMUXD_API is updated to always be __declspec( dllexport ) when compiling with Visual C++.
  • Some #include statements were not compatibile with Visual C++ and this has been fixed. A lot of unistd.h includes were redundant and the have been removed.
  • A msc_config.h file, which defines values such as _CRT_SECURE_NO_WARNINGS which work around Visual C++ compiler errors, and defines macros, functions,... that don't exist when compiling with the Visual C++ compiler. For example, func is defined as FUNCTION.. This header must be included before any other header is included in the file; it is usually added right after the config.h header.
  • A msc_compat.h file, which overrides function definitions in C++ that create compiler errors. For example, using strdup in Visual C++ creates an error asking you to use _strdup instead. This file defines strdup as _strdup, working around the issue.
  • Packing structs is compiler-specific and this has been accounted for

The updated code compiles on Linux (see Travis Build ) and Windows (see AppVeyor Build )

Add msc_config.h file which contains definitions for inline, __func__ and various definitions that make the Visual C++ compiler be compatible with the libusbmuxd codebase

collection.c, socket.c, libusbmuxd.c: Include msc_config.h
Move config.h, msc_config.h to the top o
Packing structs is done differently on MSVC and GCC
Visual C++ requires the declaration of methods to be exactly the same in the .h and .c files; otherwise it throws C2375.

This is fixed by:
- Defining USBMUXD_API_MSC in the public headers (via usbmuxd.h) which will add __declspec( dllexport ) to all method definitions in the public headers when compiling with Visual C++
- Ensuring USBMUXD_API_MSC is always set to __declspec( dllexport ) in the private source files when compiling with Visual C++.

Using USBMUXD_API in the public headers does not work, becuase its value depends on HAVE_FVISIBILITY, which may be defined in config.h, which is not a public header.
Include unistd.h in libusbmuxd.c
Define strcasecmp for Visual C++ compat
Include unistd.h on non-WIN32 builds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants