I am in the process of creating a visual studio solution to wrap the command-line portions of OCaml. In the standard OCaml make file there is the following target:
version.h : ../VERSION
echo "#define OCAML_VERSION \"`sed -e 1q ../VERSION`\"" > version.h
which I was hoping to simulate via a custom build event. I have modified my vcproj file to include the following lines:
<CustomBuildStep>
<Command>C:\Windows\System32\sed.exe -e "1 s/^/#define OCAML_VERSION " "$(SourceDir)VERSION" > "$(SourceDir)version.h"
</Command>
<Inputs>VERSION</Inputs>
<Outputs>version.h;%(Outputs)</Outputs>
<Message>Building version header file ....</Message>
</CustomBuildStep>
I do have sed installed on my system (from unxutils), and the command does work correctly from a command terminal (after macro-expansion naturally). However, when I execute it from inside Visual Studio I get the following error message:
CustomBuildStep:
Description: Building version header file ....
'C:\Windows\System32\sed.exe' is not recognized as an internal or external command,
operable program or batch file.
I've seen this problem on several forums and the proposed solution is to include the absolute path (which I did) or set the working directory to where the executable lives. Is there anything that I could do to get this to work?
Related
While trying to setup the Cap'n Proto compiler as a custom build tool in Visual Studio 2017, I came across a curious behavior, it only seems to work when called directly and not through a batch file.
What I first tried was, for each .capnp file, set the following Custom Build Tool settings:
Command line: "$(SolutionDir)run_capnpn.bat" compile -oc++ "%(FullPath)"
Description: Executing capnp.exe on %(Identity)...
Outputs: %(Identity).c++;%(Identity).h
I made the batch file because I wanted to avoid polluting my %PATH% with the capnp folder, this is what it contains:
#echo on
echo %*
SET PATH=%PATH%;C:\GitHub\capnproto\bin\c++\src\capnp\Debug
start /wait "" capnp.exe %*
exit /b %errorlevel%
However, with this setup the Custom Build Tool was only called on 1 of the 5 capnp files in my solution (all 5 files had exactly the same settings). I know this because only one pair of generated files appeared and only one message appeared in my build log.
Even weirder, if I compiled again it would do the next file, and on the following compile it would do another file. In all, it would take 5 compiles (one per file) before it considered everything to be fully built and stop calling the custom build tool.
After much trial and error and some help from other programmers on Discord, I tried adding capnp.exe to my path and call it directly (instead of going through the batch file) so for each capnp fil I changed the command line setting to:
capnp.exe compile -oc++ "%(FullPath)"
and now it all builds correctly. Is it possible to call a custom build tool through a batch file? and if so how?
I'm trying to build libpng-1.16.6 as a static lib from VS 2010. I think I've ruled out makefile syntax issues, file system permissions and incorrect LIB/LIBPATH environment variables. The makefile is the unchanged makefile.vcwin32 delivered with lpng1616. I'm certain the issue is environmental, but am out of ideas as to what it is. I'm looking for fresh ideas! TIA for any assistance.
Pertinent facts:
The overall pattern is the same I've used to build geos, gdal and wxWidgets open source projects: A Visual Studio makefile project calls a Windows command file. The Windows command file does any required preprocessing, calls vcvarsall.bar to set up the VS build environment, calls nmake, and performs any required postprocessing. The command file is largely the same, but customized, for each project. The makefile in each case is the one delivered with the source code. A successful retest of my wxWidgets build proves that there has not been an environmental change on my computer causing the libpng failure.
The log output of interest is:
lib -nologo -out:libpng.lib png.obj pngerror.obj pngget.obj pngmem.obj pngpread.obj pngread.obj pngrio.obj pngrtran.obj pngrutil.obj pngset.obj pngtrans.obj pngwio.obj pngwrite.obj pngwtran.obj pngwutil.obj
LINK : fatal error LNK1104: cannot open file 'libpng.lib'
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\lib.EXE"' : return code '0x450'
Explanation of the log output: Lib.exe is asked to produce libpng.lib from the list of object files. The error is that the output file cannot be open. At this point in the execution of the makefile all object files have been generated, which I have confirmed are present. The library is to be written in the same directory as the object files.
Since the compiler is able to write the object files, there cannot be a write permissions issue in this directory.
Starting a VS command prompt window, navigating to this path and executing the same 'lib' command line the makefile is executing succeeds. Therefore there cannot be a command line syntax error. Running the nmake from the Windows command file from this same VS command prompt also succeeds.
Adding the 'lib' commandl line to the Windows command file immediately after execution of the makefile results in the same error as when run from the makefile.
The natural conclusion is that the problem is the environment in which lib.exe is being executed.
Google results, searching on combinations of 'lib', 'link', 'lnk1104', '0x450', 'nmake', 'makefile', 'makefile.vcwin32', 'works in command line, not in makefile', etc., reveal several patterns. As one would expect, the most common problem is that one of the input files is missing or invalid. (See 3, 4, 5 and 6 above.) I haven't noticed a single case where the file cited in the error message is actually the output file, not an input file. Another common issue that something is wrong with the LIB or LIBPATH environment variables. (I've examined these, comparing the VS command prompt values with the ones from my workflow.)
I've found that apparently lib.exe writes its output to the default output name and renames to the name requested by the '-out' option. If the makefile is altered to build 'tmplibpng.lib' instead of 'libpng.lib' the same error message is generated.
I thought I was being safe. When writing Windows command files I prefix and suffix all 'internal' environment variables with underscore characters to avoid collisions, for example, 'LIB'. Apparently 'LIB' is in use by lib.exe, though it's not in Microsoft's published list. Renaming this environment variable solved my problem.
I am debugging c++ console application with Visual studio. I exhausted of inserting the same input every time I debug this program. I would like to use the same input more times.
I do this without debugging in command line with command: Program.exe < 1.in
Is it possible to use debugging with standard input redirected from file???
I already tried looking in to procejt properties. I tried setting Command to $(TargetPath) < 1.in instead of $(TargetPath).
I also tried setting Command Arguments to < 1.in. Niether of these method worked.
I am using Visual Studio 2012. But this is probably same in all versions of studio.
This is a supported debugging scenario. You do have to make sure that the debugger can find the file. Leave the Command setting at $(TargetPath). A possible value for the Command Arguments setting is:
< "$(ProjectDir)test.txt"
if the input file "test.txt" is located in the project directory. Or type the full path of the file to be sure. The MSDN article that describes this feature is available here.
I just create a file called stdin.txt in the project
1) set the Build Action to Content
2) Copy to Ouput Directory: Copy if newer
Then when you build stdin.txt is copied to the same folder as the executable.
Then in project properties debug|command line arguements enter the following
< stdin.txt
There is no need to use a path macro
If you don't want to mess with the the path you can add a new file with a right click on the source files folder in the solution explorer and then paste to it the content from the wanted file. And then change the command argument to the new file name.
I currently use the following cleartool command using Visual Studios External tool interface:
Command: \installationpath\cleartool.exe
Arguments: annotate -nheader $(ItemPath)
Initial directory: $(ItemDir)
I do use the output window. Which will let that command print out the location of the .ann file it produces. I'm wondering if there is a way for Visual studio to auto open that produced file?
In this case its not a huge hardship to copy the location and open the file. I'm just always looking for ways to make things easier.
Using just one external tool, you wouldn't be able to execute cleartool, and to open a file (generated from the cleartool command).
You can open a file from a Visual Studio External Tool as explained here, but that wouldn't execute cleartool.
So I would recommend executing a script (.bat, .cmd, .vbs) in order to:
do the cleartool command you want
open the generated file.
You would pass to this script no only $(ItemPath), but also, depending on where it is generated, $(ItemDir), or $(ProjectDir), or $(SolutionDir), or $(TargetDir).
I realize this is going to be an exotic question, but I just can't find the answer.
I'm trying to fix up and enhance an old visual basic-based application.
My problem is: where is the output directory with the compiled binaries?
Thanks.
If some clarification is needed, please ask.
In the .VBP, if there is a line specifying the path like this
Path32="C:\"
Then the resulting EXE will be built at that location. Otherwise, it will be built in the same directory as the .VBP file. The path can be relational as well and may not be a fully qualified path.
I think you want the /outdir switch. This overrides the Path32 setting in the Project file.
VB6[.EXE] [[{/run | /r}] | [/runexit] | [{/make | /m}] projectname]
[/out filename] [/outdir path] [/d const=value{[:constN=valueN]}]
[/mdi | /sdi] [{/cmd argument | /c argument}]
Options:
/run or /r projectname Tells Visual Basic to compile projectname and run it,
using the arguments stored in the Command Line
Arguments field of the Make tab of the Project
Properties dialog box.
/runexit projectname Tells Visual Basic to compile projectname and run it.
Visual Basic will exit when the project returns to
design mode.
/make or /m projectname Tells Visual Basic to compile projectname and make an
executable file from it, using the existing settings
stored in the project file.
/out filename Specifies a file to receive errors when you build using
/m or /runexit. If you do not use /out, command line
bild errors are displayed in a message box.
/outdir path Specifies a directory path to place all output files in
when using /make. This path must already exist.
/d or /D const=value... Tells Visual Basic which values to use for conditional
compilation constants when making an .EXE or ActiveX
component with the /make switch. Separate multiple
constants with colons.
/cmd or /c argument Specifies a command string to be passed to the Command$
function. When used, it must be the last switch on the
command line.
/mdi or /sdi Changes the Visual Basic environment to either Single
Document Interface (SDI) or Multiple Document Interface
(MDI) mode. Visual Basic remains in this mode until
you change it.
/? Displays a list of valid command line switches.
You may use a group name in place of projectname in any of the above switches.
Works fine here.
There is no equivalent 'bin/lib' output directory for VB6. When you compile a VB6 project, the default is to compile to the same folder as the project (vbp file). It is also possible to compile to any other folder available to the user.