[VS2010] adding *.dll files to a project

This is a discussion on [VS2010] adding *.dll files to a project within the C++ Programming forums, part of the General Programming Boards category; I am writing a C++ application in Visual Studio 2010 which is meant to use MATLAB for graph plotting. In ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    19

    [VS2010] adding *.dll files to a project

    I am writing a C++ application in Visual Studio 2010 which is meant to use MATLAB for graph plotting. In order to do so I added the MATLAB dll directory in my solution:
    Properties -> Debugging -> Environment -> "PATH=F:\MATLAB R2010b\bin\win32"
    as well as in:
    Properties -> Linker -> Input -> Additional Dependencies:
    "F:\MATLAB R2010b\extern\lib\win32\microsoft\libeng.lib
    F:\MATLAB R2010b\extern\lib\win32\microsoft\libmx.lib"

    I also needed to include headers to MATLAB engine:
    Code:
    #include "engine.h"
    #include "matrix.h"
    #include "tmwtypes.h"
    When I run my program directly from VS (start without debugging) it works properly, however if I build the app and then start the executable, it gives me an error:
    Could not locate something.dll
    I tried to copy the file from the directory mentioned above but then it asks for another and another until I got tired of copying all the libraties. I copied the executable to the directory "F:\MATLAB R2010b\bin\win32" and then the program works properly.

    How can I make VS copy all the files for me or somehow tell the program to look for them in the matlab directory? What is the common programming practise on handling the dll libraries?
    Last edited by kulfon; 06-26-2011 at 08:33 AM.

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Did you add it as a reference to your project? I found this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Quote Originally Posted by kulfon View Post
    Properties -> Debugging -> Environment -> "PATH=F:\MATLAB R2010b\bin\win32"
    ....
    When I run my program directly from VS (start without debugging) it works properly, however if I build the app and then start the executable, it gives me an error:

    I tried to copy the file from the directory mentioned above but then it asks for another and another until I got tired of copying all the libraties. I copied the executable to the directory "F:\MATLAB R2010b\bin\win32" and then the program works properly.

    How can I make VS copy all the files for me or somehow tell the program to look for them in the matlab directory? What is the common programming practise on handling the dll libraries?
    Environment variables are not compiled/linked in to the application itself. They are passed as "arguments" when visual studio invokes your application. When you are executing your application manually that PATH variable isn't the same anymore.

    The solutions I can think of are:
    * Have the dlls in the same directory as your application.
    * Have the dlls in the search path. How to set the path in Windows 2000 / Windows XP.
    * Don't link with the static libraries and load the dlls manually with LoadLibrary() by using absolute paths to the dlls. But this would require that everyone trying to run your application has MATLAB installed in the same path as you, unless it sets some registry key to it's install dir which you can use.

    Quote Originally Posted by AndrewHunter View Post
    Did you add it as a reference to your project? I found this.
    That link is referring to .Net assemblies, not native dlls.

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Oh, ok. Thanks Mike.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL: Port Issue from VS6 to VS2010
    By cnfwriter in forum C++ Programming
    Replies: 11
    Last Post: 04-13-2011, 09:56 AM
  2. VS2010 C++/CLI Bug
    By nvoigt in forum C++ Programming
    Replies: 3
    Last Post: 10-15-2010, 10:27 AM
  3. VS2010 vs VS2008
    By zacs7 in forum General Discussions
    Replies: 29
    Last Post: 06-13-2010, 02:40 AM
  4. MSLU? Need help adding this in to project.
    By MidnightlyCoder in forum C++ Programming
    Replies: 1
    Last Post: 03-13-2006, 12:07 PM
  5. help, linker errors when adding library file to project
    By ngcfan525 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2003, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21