Jump to content
  • Advertisement
Sign in to follow this  
Sepiantum

Best way to link against a library within a subproject

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So let's say you have a solution, and then multiple projects within that solution. One of those projects happens to be compiled into a .dll that will be used by another project. What would be the best way for the project importing the .dll symbols to link to the .lib file?

Share this post


Link to post
Share on other sites
Advertisement
Isn't that handled automaticly if you setup project dependencies, unless you explicitly tell it not to link dependencies or something?

To setup dependencies, right-click solution and select Project Dependencies (or whatever). If that's not enough, add the lib to the project settings but keep the dependency anyway. I haven't tried this in many years since I now use C# in which it's much easier (imho).

Share this post


Link to post
Share on other sites

Specify the lib file as a linker input in the other project?


Yeah well, using #pragma comment(lib, "...") leads to a lot of ..\\..\\..\\ stuff inside the quotes. I'm wondering if there's a way to avoid that without copying libraries everywhere.

Share this post


Link to post
Share on other sites
Can't you output the result of the library compile to "../../../myOtherProject/libs", so it's outputted into the other project's folder or subfolder, and that project can just specify a more natural path like "libs/myLib.dll"?

GCC allows that, I'm certain Visual Studio would also.
In GCC, using the command line, when specifying what to name the resulting object ("myApp.exe") you can also give it a path ("../otherLocation/myApp.exe").

Share this post


Link to post
Share on other sites
Also, how does one detect if he is in 64 bit or 32 bit configuration and or debug? For the debug, a simple #if defined (DEBUG) || defined (_DEBUG) would suffice, but I can't seem to find anything like _WIN64, and _WIN32 always seems to be defined.

Share this post


Link to post
Share on other sites
Hidden
Also, how does one detect if he is in 64 bit or 32 bit configuration and or debug? For the debug, a simple #if defined (DEBUG) || defined (_DEBUG) would suffice, but I can't seem to find anything like _WIN64, and _WIN32 always seems to be defined.

Share this post


Link to post
In your project, you can add preprocessor defines yourself for different targets, and you'll have different targets for different platforms (ie x86 vs x64). All that differs between them should be settable in the project settings though, you shouldn't need any #ifdefs for it.. Why do you need that?

Also, the project dependency thing also makes sure the build order is correct and (I assume) doesn't run the current .exe if the .dll fails to build. If this is enough to link dependent projects on your dll, it'll also solve it for debug/release and x86/x64.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!