MADEAPPS / newton-dynamics

Newton Dynamics is an integrated solution for real time simulation of physics environments.
http://www.newtondynamics.com
Other
938 stars 182 forks source link

Make use of dynamic linker optional #213

Open JayFoxRox opened 4 years ago

JayFoxRox commented 4 years ago

I'm statically linking Newton, and to my surprise it will still LoadLibrary, GetProcAddress and FreeLibrary at runtime:

https://github.com/MADEAPPS/newton-dynamics/blob/fd2c31db491cda38612649809c5f4341f7f7393a/sdk/dgPhysics/dgWorldPlugins.cpp#L146-L150

(The functions called from here, and associated headers are also problematic as they pull in unportable functions which could be avoided if plugins weren't a feature)

The goal of static linking (in my particular case) is to avoid any use of the dynamic linker, because the target platform, original Xbox (while being win32), does not actually have a dynamic-linker (although I might eventually implement one myself). But also for other platforms, I expect that not everyone wants (or requires) plugins.

For portability, it would be nice if WorldPlugins could be made optional in the CMake configuration.

JulioJerez commented 4 years ago

right again, I no added preprocessor DG_USE_PLUGINS for optionally adding plugins. the hand made buidl have the on by default but teh cmake script can configure them optimally.

JayFoxRox commented 4 years ago

I did not try this switch yet, but I reviewed the commit and noticed that the linux headers will still be included, even if DG_USE_PLUGINS is defined; so for linux-like platforms, people would still have to provide dummy header files, even if they don't have a dynamic linker (and despite the headers being unused).

JulioJerez commented 4 years ago

The linus header are needed for any posit type system ther are not conditional on teh plugins. as far as I knwo they are under teh Linux prepprocessor.

if linux

include

include

endif

JayFoxRox commented 4 years ago

There might be POSIX subsets which do not have a dynamic linker, and they will not even provide dlfcn.h, so compilation would fail, even if DG_USE_PLUGINS isn't defined.

But if DG_USE_PLUGINS is not defined, then dlopen, dlsym, .. etc. are never actually used. The same applies to opendir: the code which contains them is disabled because DG_USE_PLUGINS is not defined. So including <dlfcn.h> and <dirent.h> is not necessary. It's only necessary when plugins are enabled.

If you include them regardless (even if they are unused) then they must still exist. This just forces people to create an empty dlfcn.h and empty dirent.h to compile newton-dynamics - this shouldn't be necessary and could be easily avoided.

JulioJerez commented 4 years ago

I do not know what that would be a problem, but ok, I added this

if defined(DG_USE_PLUGINS) && defined(linux)

include

include

endif