question

DanielLonsdale-5496 avatar image
0 Votes"
DanielLonsdale-5496 asked DanielLonsdale-5496 commented

Visual Studio 2019: CL.exe use of "command files" for /I additional includes - how to get working?

I am trying to test a folder layout for large projects with many dependencies, to ensure I get this right in a basic setup first, before manually pulling in many many files and placing them in set locations.

One way of controlling all the source and header files' locations is by using CL command files, as described quite clearly here:

https://docs.microsoft.com/en-us/cpp/build/reference/cl-command-files

Consequently, I arranged my folder structure as I believe best reflects my requirements, (eg) as follows within c\users\me\source\repos\:

TestProject

ExternHeaderGroup1 - to hold dependency headers, and in this case, also "Header1.h" for testing
ExternHeaderGroup2
..
ExternSrcGroup1 - to hold dependency source
ExternSrcGroup2
...
Projects - to hold many diff projects that all use the dependencies

Windows

TestProject1 - has .sln file

TestProject1 - has .vcxproj file and "main.cpp" calling up "Header1.h"

LocalHeaderTestFolder
LocalSrcTestFolder

...

OtherTargetPlatform

...

Next, I create an ExternFilesLocations.txt, containing the text:

/IC:\Users\me\source\repos\TestProject\ExternHeaderGroup1\

This file was placed alongside main.cpp and .vcxproj files.

(Nb #1 and Nb #2 here)

Then, in visual studio, TestProject1 -> right click 'properties' -> configuration properies -> C/C++ -> General -> Additional Include Directories, I place the text:

@ExternFilesLocations.txt

This resolves into a cl command line of:

/JMC /external:env:"EXTERNAL_INCLUDE" /permissive- /ifcOutput "x64\Debug\" /GS /W3 /Zc:wchar_t /I"@ExternFilesLocations.txt" /ZI /Gm- /Od /sdl /Fd"x64\Debug\vc142.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /showIncludes /MDd /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\TestWildcardProject1.pch" /diagnostics:column


It appears that the compiler never finds (but never complains that it cannot find) the ExternFilesLocations.txt file. No variations of hard-coded/relative links, ExternFilesLocations.txt location etc seem to be recognised.

I also tried simplifying calling cl.exe from the Visual Studio command prompt with options such as;

c:\users\me\source\repos\testproject\projects\windows\testproject1\testproject1\> cl.exe \I@ExternFilesLocations.txt main.cpp
c:\users\me\source\repos\testproject\projects\windows\testproject1\testproject1\> cl.exe \I"@ExternFilesLocations.txt" main.cpp

and other variations described below.

In all cases, cl.exe will not find Header1.h.

Please let me know what I am missing?


Nb. #1 - I also tried changing the ExternFilesLocations.txt text to :
/I"C:\Users\me\source\repos\TestProject\ExternHeaderGroup1\"
/I"......\ExternHeaderGroup1\"
/I......\ExternHeaderGroup1\

Nb. #2 - I also put the ExternFilesLocations.txt file in c:\ root and use the additional include directories as
@c:\ExternFilesLocations.txt


c++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered DanielLonsdale-5496 commented

Try removing your current option, then add @ExternFilesLocations.txt to Additional Options field of C/C++, Command Line tab. The file must contain the /I"…" lines.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Viorel-1,

Thanks for the quick response, but that didnt work...

  1. I removed the Properties->Config Properties->C/C++->Additional Include directories text so that the field is now blank.

  2. I added to Properties->Config Properties->C/C++->Command Line->Additional Options @ExternalFileLocations.txt

  3. I ensured the file contents had /I"C:\Users\me\source\repos\TestProject\ExternHeaderGroup1\"

I also tried, in step 2:

/I@ExternalFileLocations.txt
/I"@ExternalFileLocations.txt"
/I@"ExternalFileLocations.txt"

I can see that all 4 different versions are passed on to cl, I quote:

"
1> C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\CL.exe /c /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc142.pdb" /external:env:EXTERNAL_INCLUDE /external:W3 /Gd /TP /showIncludes /FC /errorReport:prompt /I"@ExternalFileLocations.txt" Main.cpp
"

... so, it looks to be passed along okay, but not accounted for...



0 Votes 0 ·
Viorel-1 avatar image Viorel-1 DanielLonsdale-5496 ·

On Step 2 you should add @ExternFilesLocations.txt without /I. The final command line should not show /I@ExternFilesLocations.txt. Make sure that you do it for corresponding Configuration (e.g. “Debug”) and Platform (e.g. “x64”).


0 Votes 0 ·

Ha!!

It worked!!!

I'm stumped as I only went back to how it was set up about 5 mins back. No clue how I didnt get it working before.

Anyway!!!!! Thank you for the guidance. I'll have a play around with this to ensure I have noted everything before marking your answer accepted.

Thank you once again. :-D

0 Votes 0 ·