Hello,

I was trying to compile Agar dynamic libraries with VS 2010 as the
precompiled Windows DLLs are missing exported symbols. Static linking
is not an option for my project. I use the source code distribution
for MSVC downloadable on the libagar.org site. However, there were
some obstacles I'd like to discuss.

First, a file config/have_png.h seems to be missing in the MSVC
project archive. I commented out the include on line 40 in
gui/load_png.c to bypass this.

There are still no symbols exported from the freshly compiled DLLs
because the export declaration is missing. The reason is, that the
appropriate #define in core/begin.h (and gui/begin.h) is never
reached. MSVC does not define __WIN32__ but _WIN32 when the
preprocessor is run. I added this in begin.h and now most symbols get
exported.

Some are still missing, however, because each header file seems to
come in two flavors: one with the DECLSPEC in the include subfolder
and one without the DECLSPEC in the same folder as the C source files
(are there any more differences between them?). For example, agConfig
is defined in core/core.c which includes "config.h" where the DECLSPEC
is missing. Thus, agConfig is not exported from ag_core.dll. If I
change the include directive to look for <core/config.h> instead, it
works. AG_Snprintf, AG_LabelNew and more are not exported for the same
reason.

Maybe agConfig and others (e. g. agClassTree) should not be public to
other assemblies (I'm not an expert with neither Agar nor C
development) to prevent unwanted modification? But they are accessed
by ag_gui. In the distributed MSVC project files ag_gui references
ag_core_static which probably means that ag_gui.dll links statically
against ag_core_static.lib. This lead to access violations because of
null pointers when I tried to use both DLLs dynamically: AG_InitCore
initialized the class tree in ag_core.dll space but AG_InitGraphics
used the class tree statically linked in ag_gui.dll which was still
uninitialized. But I cannot drop ag_core.dll either because ag_gui.dll
does not export the core functions (which it statically carries).

What is the desired architecture here?  I expected ag_gui.dll to
depend on ag_core.dll and use the variables exported from there (which
requires the header inclusion changes described above). That's why I
changed the reference in ag_gui from ag_core_static to ag_core (the
DLL project) and edited the begin.h headers once again to have the
DECLSPEC be __declspec(dllimport) if the header is externally
included. (You'll find what I ended up with in include/core/begin.h
below.)  Now I can at least invoke AG_InitCore and AG_InitVideo
successfully with dynamically loaded core and gui DLLs but there are
more unexported symbols like AG_LabelNew, AG_Getopt and probably more.

With regards,
Jakob

PS. has the Wiki gone permanently? It's unreachable at the moment and
I can't find an obvious link from libagar.org anymore.

--- relevant part of include/core/begin.h with adaptions described above ---
# elif defined(__WIN32__) || defined(_WIN32)
#  ifdef _AGAR_CORE_INTERNAL
#    ifdef __BORLANDC__
#      define DECLSPEC
#    else
#      define DECLSPEC  __declspec(dllexport)
#    endif
#  else
#    define DECLSPEC    __declspec(dllimport)
#  endif

I don't know whether this is correct for the ex-Borland compiler.
Equivalent changes applied to include/gui/begin.h as well with the
other internal definition, of course.

_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html

Reply via email to