0

I realize that similar questions were posted earlier but I need slightly different solution.
I have VS2012 C++ project A.vcxproj,that has debug1 configuration( platform x64) , and it builds corresponding .exe. It also uses a dll from other VS2012 C project B.vcxproj from a path that must be added to the environment variables. A.vcxproj.user file has following text

<LocalDebuggerEnvironment>PATH=%PATH%;C:\Program Files\libsndfile\bin;..\..\lib\simulink\;$(LocalDebuggerEnvironment)  </LocalDebuggerEnvironment>

I need to add this setting automatically to the "A"project with following constraints

  1. I cannot export user file as it as "per user", so cannot upload to our SCM system where other users can download it.
  2. I tried adding code in main function, something like

    _putenv("PATH = ....\lib\simulink");
    but this does not work, as before the main file is compiled, it needs to search for the dll from specified path, which it dosn't .

Can anyone suggest a easy, portable fix , that i could distribute to all users through SCM, along with the project file.

I have also tried following:
--Created batch file setpath.bat with following content

@ECHO %PATH%  set PATH = %PATH%;C:\Program Files\libsndfile\bin;C:\dev\lib\simulink 

-- added to A.vcxproj settings->build event->Pre-build->Command line

call  C:\setpath.bat

and I don't see the added paths under vS op window. neither does the VS User file gets the change, and running the project complains for missing dll error.
--I tried to execute the batch file in
A.vcxproj settings-> Custom build step->Execute before "Run"
and still no result.

I guess the solution needs to add needed path to current environment variable for the time VS project is "run".

Thanks
sedy

imbr
  • 6,226
  • 4
  • 53
  • 65
user915783
  • 689
  • 1
  • 9
  • 27
  • If nobody can agree where this DLL needs to be stored then this cannot work of course. Makes you wonder how this can ever come to a good end on the user's machine. The trivial solution is to simply add the C project to the solution. Now the DLL ends up where it belongs automatically. – Hans Passant Jul 22 '15 at 03:46
  • @HansPassant These 2 projects need to be separate for various reasons, otherwise I would have done as you suggested – user915783 Jul 22 '15 at 16:57

2 Answers2

1

added to A.vcxproj settings-> Build Events ->Pre-Build event

call setdllpath.bat

where the file contains the following:

@ECHO %PATH%
set COMSPEC = "%VCINSTALLDIR%\vcvarsall.bat" amd64
setx PATH "C:\Program Files\libsndfile\bin;..\..\lib\simulink" 
@ECHO %PATH%

So, once I build the Project, close Visual studio and open it again, and run the files wiithin project, it picks up dll correctly.

user915783
  • 689
  • 1
  • 9
  • 27
0

Contents in *.vcxproj.user, *.vcxproj.user or *.props use the same xml schema so can be easily exchanged or included.

First if usefull you can add UserMacros to define the path to your libraries. Like bellow for the following two variable

PYTHONHOME=$(USERPROFILE)\AppData\Local\Programs\Python\Python37
PYTHONPATH=$(PYTHONHOME)\DLLs;$(PYTHONHOME)\Lib;$(PYTHONHOME)\Lib\site-packages

Edit the .vcxproj adding inside <Project>:

  <Project .... >
  ...

  <PropertyGroup Label="UserMacros">
  <PYTHONHOME>$(USERPROFILE)\AppData\Local\Programs\Python\Python37</PYTHONHOME>
  <PYTHONPATH>$(PYTHONHOME)\DLLs;$(PYTHONHOME)\Lib;$(PYTHONHOME)\Lib\site-packages;</PYTHONPATH>      </PropertyGroup>

  ...
  </Project>

After you can add inside your build configuration, the following to set the $(Path) variable.

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <LocalDebuggerEnvironment>Path=$(Path);$(PYTHONHOME);$(PYTHONHOME)\DLLs;$(PYTHONHOME)\Lib;$(PYTHONHOME)\Lib\site-packages;$(PYTHONHOME)\Scripts;$(PYTHONHOME);</LocalDebuggerEnvironment>

imbr
  • 6,226
  • 4
  • 53
  • 65