mingw-cross-env-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Mingw-cross-env-list] Undefined reference to freeglut libraryfuncti


From: Martin Lambers
Subject: Re: [Mingw-cross-env-list] Undefined reference to freeglut libraryfunctions
Date: Sat, 18 Dec 2010 17:32:14 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7

On 17/12/10 10:41, Volker Grabsch wrote:
> The preferred solution is to compile the code with
> 
>     gcc ... -DFREEGLUT_STATIC ...
> 
> That's how the library is meant to be used. And that's how many
> other libraries are meant to be used.

That is true, but there is a better solution.

Gcc does not really need the "__declspec(dllimport)" attribute when
using DLLs (see the documentation of "dllimport" here:
<http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>.

This means that when using gcc, it is not necessary to treat static
libraries and DLLs differently. This is only required for MSVC (Visual
Studio).

A library libfoo can use the following in its header:

8<------------------------------------------------------------
#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
#   ifdef LIBFOO_BUILD
#       ifdef DLL_EXPORT
#           define LIBFOO_EXPORT __declspec(dllexport)
#       else
#           define LIBFOO_EXPORT
#       endif
#   else
#       if defined _MSVC && !defined LIBFOO_STATIC
#           define LIBFOO_EXPORT __declspec(dllimport)
#       else
#           define LIBFOO_EXPORT
#       endif
#   endif
#else
#   define LIBFOO_EXPORT
#endif

LIBFOO_EXPORT void foo_init(void);
LIBFOO_EXPORT int foo_version(void);
...

8<------------------------------------------------------------

When building the library, LIBFOO_BUILD is defined, and when building a
DLL, additionally DLL_EXPORT is defined. This ensures that the dllexport
attribute is set where necessary.

A program that uses the library and is compiled with gcc does not need
to care about whether the library is static or a DLL. Only if the
program is compiled with MSVC, LIBFOO_STATIC must be defined to use the
static version, but that is irrelevant to Mingw-cross-env.

Martin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]