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

Static build with Visual Studio #616

Closed
tanshihaj opened this issue Oct 24, 2020 · 3 comments · Fixed by #658
Closed

Static build with Visual Studio #616

tanshihaj opened this issue Oct 24, 2020 · 3 comments · Fixed by #658
Assignees

Comments

@tanshihaj
Copy link

I'm wonder is it possible to build static version of libiio using Visual Studio compiler? Currently when I try to do it I get LNK2019 unresolved external symbol imp errors since here

libiio/iio.h

Lines 75 to 79 in 99ef201

# ifdef LIBIIO_EXPORTS
# define __api __declspec(dllexport)
# else
# define __api __declspec(dllimport)
# endif
it defines __api either as __declspec(dllexport) or __declspec(dllimport), so linker, that links this library to my test program, thinks that this symbols should be defined in .dll.

Usually if you need to link static library __api should be defined as empty:
https://github.com/substack/libssh/blob/c073979235eb0d0587ac9cb3c192e91e32d34b06/include/libssh/libssh.h#L26-L42

Is it possible to add some kind of LIBIIO_STATIC definition to make it possible to link libiio as static library?

@tanshihaj
Copy link
Author

I've tried to do it and it work in my case: tanshihaj@3b9305e

@dNechita
Copy link
Contributor

I think we can add an option to build libIIO as a static library.

@dNechita dNechita self-assigned this Oct 27, 2020
@rgetz
Copy link
Contributor

rgetz commented Nov 7, 2020

Just as a reminder - libiio is LGPL. From the GNU.org website emphasis in mine:

(1) If you statically link against an LGPLed library, you must also provide your application in an object (not necessarily source) format, so that a user has the opportunity to modify the library and relink the application.
(2) If you dynamically link against an LGPLed library already present on the user's computer, you need not convey the library's source. On the other hand, if you yourself convey the executable LGPLed library along with your application, whether linked with statically or dynamically, you must also convey the library's sources, in one of the ways for which the LGPL provides.

It's not hard/difficult - but you must comply with the obligations of the license.

pcercuei added a commit that referenced this issue Apr 1, 2021
Set the LIBIIO_STATIC define when compiling a static library, which then
causes the __api to be resolved as empty.

This fixes building statically under MSVC.

Fixes #616.

Signed-off-by: Paul Cercueil <[email protected]>
pcercuei added a commit that referenced this issue Apr 7, 2021
Set the LIBIIO_STATIC define when compiling a static library, which then
causes the __api to be resolved as empty.

This fixes building statically under MSVC.

Fixes #616.

Signed-off-by: Paul Cercueil <[email protected]>
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

Successfully merging a pull request may close this issue.

3 participants