Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to know how to link to a DLL stored in a place other than the runtime directory. The location of the directory is as follows
%LWE_HOME%/lib/engine.dll
How do I tell the program to look for it there instead of in the runtime directory?

I am looking for a cross-platform solution. If there isn't a "one size fits all" solution, please provide me with solutions for both *n*x operating systems and windows.
Posted
Updated 26-Apr-14 14:01pm
v2
Comments
[no name] 26-Apr-14 20:07pm    
I am not at all sure what it is that you are doing or trying to do. It sounds to me like a mixup of terminology. Seems to me that you could just make a call LoadLibrary at runtime.
Sicppy 26-Apr-14 20:12pm    
I don't really want to have to make function pointers for all of the functions in a DLL especially because it is object oriented
[no name] 26-Apr-14 20:24pm    
"want to" and "object oriented" is completely irrelevant. I want to have neural interface so I don't have to do all that hard typing code using a keyboard all day long. Does not mean it's going to happen. Especially when your original posting is talking about 2 completely unrelated and contradictory concepts.
Sicppy 26-Apr-14 21:50pm    
What two contradictory concepts would that be?

All of what SA has said is correct. That's why we have this:
http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx[^]

I think the best solution is put the dll where it can be found. However to achieve what you wish look at this. You can do it via registry:
http://www.codeguru.com/cpp/w-p/dll/article.php/c99/Application-Specific-Paths-for-DLL-Loading.htm[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Apr-14 19:26pm    
Right. This is useful information to be taken into account. My 5.
—SA
Sicppy 26-Apr-14 19:59pm    
Good information, which is why I rated 5, but since the solution you provided is windows only, I can't accept it as the solution.
Sergey Alexandrovich Kryukov 26-Apr-14 21:05pm    
If there are no Windows conventions of the search of the libraries, there are no cross-platform conventions.
—SA
Sicppy 26-Apr-14 21:52pm    
Windows does have a way to define it though, as he pointed out in his response, and if I end up finding the answer for n*x later in another location, then I will accept his response because it contributed to my final answer
There is no such concept as "runtime directory". There is no such concept as "linking to a DLL in an environment variable". There is no one predefined universal way of saying where to look for a DLL (I'm talking about native DLLs; .NET assemblies can be put in the well-defined Assembly Cache.)

This is one of the reasons why we have so called "DLL hell":
http://en.wikipedia.org/wiki/DLL_hell[^].

Some, say, Linux distro have strict rules for reusing components and their registration the way all installations can find out what to install and what not, but not Windows.

Now, environment variables are sometimes used for such purpose, but this way is purely application-dependent. In principle, you can develop your own system for the group of applications sharing some DLLs. I think using environment variables is a pretty bad approach; it is mostly used by legacy software (possibly created when typical computer systems had much less applications then these days) and just contaminates the system. For some background, please see:
http://en.wikipedia.org/wiki/Environment_variable[^].

—SA
 
Share this answer
 
Comments
Sicppy 26-Apr-14 19:57pm    
Well you see, I am developing a gaming engine, and the engine would be installed to one place in the computer to prevent the entire engine from being statically linked and downloaded with ever application that uses the engine. Rather, they would install the engine once, and every application that uses the engine would simply link to the pre-installed engine dll
Sicppy 26-Apr-14 19:57pm    
This is why I have the environment variable, so it knows where the engine is installed. I was going to use the registry, but it is windows only.
Sergey Alexandrovich Kryukov 26-Apr-14 21:04pm    
Environment variables are nearly obsolete and don't have any benefits. You could better use one of the predefined directories per user or "All users". The relative directory name specific to your products should be some predefined fixed string (which would be the case with your environment variable name). Avoid using environment variables by all means.
—SA
There is no common way to search for libraries...

In Windows you can use the PATH environment variable.

In Linux or Unix you can use LD_LIBRARY_PATH environment variable to specify the library's path. If the path doesn't change (this is true most of the time), you can specify the LD_RUN_PATH environment variable in your build environment. Alternatively, you can use -runpath linker option.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900