Jump to content

  • Log In with Google      Sign In   
  • Create Account

Visual Studio: Selectively include header (external APIs, ...) to project


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Juliean   GDNet+   -  Reputation: 2605

Like
0Likes
Like

Posted 27 April 2014 - 03:42 PM

Hello,

 

I want the following: To include an external project with both headers, libs and possibly DLLs to my engine, but have it included so that in case that project is not installed on the users PC, building will not fail for him. E.g. the FBX model SDK, I don't want to require ever user to install this on his PC if he is not using the FBX file format. In case FBX is missing, the project should still compile, and simply disable the FBX-conversion-routines. Is any such thing possible in MSVC (using 2013 Ultime)?



Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15698

Like
2Likes
Like

Posted 27 April 2014 - 03:50 PM

There are two basic choices here. The simple and easy choice is to ship your program with all of the DLLs it requires, and this is usually preferable.

If you want to support running without a particular DLL, you need to late-bind it. The typical tools for this are LoadLibrary and GetProcAddress. See MSDN for details.

#3 Juliean   GDNet+   -  Reputation: 2605

Like
0Likes
Like

Posted 27 April 2014 - 04:16 PM


There are two basic choices here. The simple and easy choice is to ship your program with all of the DLLs it requires, and this is usually preferable.

If you want to support running without a particular DLL, you need to late-bind it. The typical tools for this are LoadLibrary and GetProcAddress. See MSDN for details.

 

The problem is not only in the DLLs, but rather in the source too. Is it common in larger projects to ship with all the required external headers too? I assume the second method you mentioned still requires eigther the headers or really load all the functions using GetProcAddress and using them through those address pointers, which appears dissappealing at first sight :/



#4 ApochPiQ   Moderators   -  Reputation: 15698

Like
2Likes
Like

Posted 27 April 2014 - 04:20 PM

If your code is dependent on other code, then yes, anyone else trying to compile it needs both your code and the other code.

 

There are ways around this, though. You could wrap the external code in a DLL of your own, and use that as a minimal interface to the external code instead of trying to GetProcAddress all the stuff in the other DLL. This is also good insulation against ABI differences (note that if you try to pass C++ objects, throw exceptions, or allocate/free memory across DLL boundaries, you're in for nasty bugs).

 

Another option is to build your code in such a way that it has to be generated before it can be compiled, and the generation step includes detecting missing dependencies and excising code that relies on them. A lot of open-source projects do this.



#5 Juliean   GDNet+   -  Reputation: 2605

Like
0Likes
Like

Posted 27 April 2014 - 05:15 PM


If your code is dependent on other code, then yes, anyone else trying to compile it needs both your code and the other code.

 

I was kind of hoping there was a magical visul-studio-setting to avoid that, but seems I'm out of luck :(

 


Another option is to build your code in such a way that it has to be generated before it can be compiled, and the generation step includes detecting missing dependencies and excising code that relies on them. A lot of open-source projects do this.

 

That sounds interesting, how is it practically realized? Any links/tutorials/explanations you can give me?



#6 Hodgman   Moderators   -  Reputation: 30353

Like
2Likes
Like

Posted 27 April 2014 - 05:23 PM

A common solution I see is just to wrap all your FBX/etc code in something like
#ifdef MYSDK_ENABLE_FBX
And then the client can choose whether to define that token for your project or not.

#7 Juliean   GDNet+   -  Reputation: 2605

Like
0Likes
Like

Posted 27 April 2014 - 05:33 PM


A common solution I see is just to wrap all your FBX/etc code in something like
#ifdef MYSDK_ENABLE_FBX
And then the client can choose whether to define that token for your project or not.

 

That would be acceptable, undefining all the non-used code would be no problem. I would prefer some automated way though - really no way to e.g. read out if a certain system variable like from FBX is set in the preprocessor, and then #define MYSDK_ENABLE_FBX? :D Also, am I not going to also get problems with missing .lib-files etc?



#8 ChaosEngine   Crossbones+   -  Reputation: 2345

Like
0Likes
Like

Posted 27 April 2014 - 05:36 PM

Another option would be to have separate configurations (i.e. Debug, Release, DebugNoFBX, ReleaseNoFBX) and then set the FBX specific files in your project not to compile under that configuration.

 

Be aware that this can easily get out of hand if you have more than one combination you want to support, so I'm really only mentioning it for the sake of completeness.

 

Another possible route would be just to put the optional functionality in a separate lib that the user can make use of if they want to.


if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

#9 Hodgman   Moderators   -  Reputation: 30353

Like
0Likes
Like

Posted 27 April 2014 - 07:41 PM

Also, am I not going to also get problems with missing .lib-files etc?

You can specify the lib files to be linked using pragmas if you like (inside ifdefs)
e.g.
#pragma comment( lib, "foo.lib" )
 

eally no way to e.g. read out if a certain system variable like from FBX is set in the preprocessor, and then #define MYSDK_ENABLE_FBX?

There probably is!...but I've not had experience with it. On every project I've worked on, there's no part of the build process that could possibly vary based on the user's system/environment. They've always deliberately killed off such features to ensure that no matter which team member performs a build, the results will be the same. Doing professional QA is almost impossible otherwise wink.png
I can see that this feature would be very cute though when you're not working under such restrictions biggrin.png



#10 Strewya   Members   -  Reputation: 1432

Like
0Likes
Like

Posted 29 April 2014 - 08:51 AM


That would be acceptable, undefining all the non-used code would be no problem. I would prefer some automated way though - really no way to e.g. read out if a certain system variable like from FBX is set in the preprocessor, and then #define MYSDK_ENABLE_FBX? biggrin.png Also, am I not going to also get problems with missing .lib-files etc?

 

There is a way, but it requires some work on your part.

I've done something similar, which is extendable enough to work for what you want.

VS has an option where you can set up a prebuild event. In the prebuild event, call a script file (i use Lua).

In that script file, query the environment variables if a certain variable exists, and if so, generate a file (for instance, when you install the directx sdk, it generates the env. var DXSDK_DIR or some such).

If no env. variables can be queried, then you can manually search the hard drive within the script and find if the installation exists. Whether or not searching a users hard drive is nice/morally ok, i don't know. You decide.

The general idea is that you can generate a header file that you include, and if you find what you want, generate a #define statement with your MACRO of choice that indicates that something exists.


devstropo.blogspot.com - Random stuff about my gamedev hobby


#11 Jan2go   Members   -  Reputation: 795

Like
0Likes
Like

Posted 29 April 2014 - 09:58 AM

That would be acceptable, undefining all the non-used code would be no problem. I would prefer some automated way though - really no way to e.g. read out if a certain system variable like from FBX is set in the preprocessor, and then #define MYSDK_ENABLE_FBX? biggrin.png Also, am I not going to also get problems with missing .lib-files etc?

You could use a build system like CMake. I use a CMake script to determine whether the FBX SDK (and some other SDKs) are available on the computer. If the SDK is found, the include paths and libraries are added to the project files as well as a preprocessor flag.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS