Problem: I need to be able to compile a C++ project on Windows, Linux, or OSX and link in native/system libraries. For example, I need WS2_32.Lib on Windows, but not on Linux or OSX. This also needs to work across computers. So if someone has installed Windows on D: then I need to still be able to find WS2_32.Lib without changing the gradle.build file. Same goes for other operating systems.
Current work: from what I’ve seen, every single example or forum solution to a similar problem has the developer adding in a hard coded path to a PrebuiltLibraries section of the gradle.build file. Hard coding a path here will only work for me on one computer, not across many computers and operating systems. I’ve seen some solutions where it is suggested that multiple paths can be used, but this still doesn’t fix my problem where I need to be robust to different system configurations.
I think the typical solution to this problem would be to setup the default environment variables for paths (e.g., LD_LIBRARY_PATH, LIBPATH, LIB, etc.) with the paths to all of the libraries I need to find (i.e., push the ‘find’ portion of the task onto system configuration). The compiler/linker should then take over and be able to use the default path to find the appropriate libraries. This solution would work for me, even if it isn’t 100% ideal (100% ideal would be no configuration). However, I’ve tried that approach and it doesn’t seem to work with gradle. Does gradle overwrite those and have its own way of inputting those? Is there some other environment variable I should set to work with gradle? I haven’t been able to find a good answer to those questions so far.
My next hope is to try pulling in the environment variables myself and setting the library path via cppCompiler.args. I’m verifying that as a solution right now, but is there a better way of doing this that I’m just not seeing?