Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Make it build for windows #31

Open
jimsch opened this issue Jun 8, 2015 · 2 comments
Open

Make it build for windows #31

jimsch opened this issue Jun 8, 2015 · 2 comments

Comments

@jimsch
Copy link
Contributor

jimsch commented Jun 8, 2015

This is partly done, but there are still some thing to be finished.

If the system builds a DLL rather than a static library, the symbols to be exported from the DLL need to be identified. There are two ways of doing this:

  1. Create a file which lists the points to be exported.
  2. Use a compiler directive to tag which points are to be exported. (See http://www.cmake.org/Wiki/BuildingWinDLL for a fuller description of what this involves.)

The second method makes it clear what is happening, but makes the code be messier so you end up with code the following in cn-cbor.h

MYLIB_EXPORT
cn_cbor* cn_cbor_map_create(CBOR_CONTEXT_COMMA cn_cbor_errback *errp);

The first method means that people who only develop on Linux systems will have no clue that there is one additional step that needs to be done if a new entry point to the library is added.

I can easily do either method, and I don't think that I currently have a preference. There is no need to mark things as imports from a dll in order to link to a library. But we don't currently process cn-cbor.h to produce an internal and external version.

@despair86
Copy link

despair86 commented Jul 6, 2018

To get the UNIX devs on board, one could start out by prefixing

__attribute__ ((visibility ("default")))

to public API symbols, and a buildscript that automatically processes the header to replace that with a proper macro definition (so as not to leave Microsoft C users behind)

/* this should cover most if not all compilers in existence that target Windows NT. Including Watcom. */
#if defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) || defined(__NT__)
#	ifdef API_EXPORTS
#	define CNCBOR_API __declspec(dllexport)
#	else
#	define CNCBOR_API __declspec(dllimport)
#	endif
#else
#	ifdef API_EXPORTS
#	define CNCBOR_API __attribute__((visibility("default")))
#	else
#	define CNCBOR_API
#	endif
#endif // defined

I use Clang or GCC even on Windows, so either of these work fine on my end.

@sbertin-telular
Copy link

attribute ((visibility ("default"))) is not supported by all compilers. For example, the IAR ARM compiler I use does not support it, The proposed checks need to be modified to only use that for compilers that support it.

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

No branches or pull requests

3 participants