MSBuild fatal error C1083: Cannot open include file - msbuild

I know there are others subjects on this, but none of their solutions worked for me.
I have this simple code :
#include "stdafx.h"
#include "AccurateTimeStamping.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
I would like to build it using MSBuild. The following header is in another directory
AccurateTimeStamping.h
I already successfully build this project using MSBuild and environnement variable. But I want to avoid env variable. In command line I did this :
D:\propTest>msbuild.exe propTest.sln /p:ReferencePath=M:\Utils\include
Or this
D:\propTest>msbuild.exe propTest.sln /p:AdditionalIncludeDirectories=M:\Utils\include
Or This
D:\propTest>msbuild.exe propTest.sln /p:"ReferencePath=<M:\Utils\include>"
Or this :
D:\propTest>msbuild.exe propTest.sln /p:includepath=M:\Utils\include
But I still have :
d:\proptest\proptest\proptest.cpp(5): fatal error C1083: Cannot open include
file: 'AccurateTimeStamping.h': No such file or directory
I can not modify the projects that I have to build and I can't change .vcxproj.
Is there a way to pass the path of .h files to MSBuild using only command line and no env var??
Any help would be greatly appreciated !

Related

Make(compiler) complains about missing llvm/PassAnalysisSupport.h file

I downloaded LLVM (12.0.1) from the script file llvm.sh which they have now started to include on their Debian downloads page.
Ran clang and everything was working as expected(good job dev team I guess?).
The installation script installed LLVM in /usr/lib/LLVM-12/ and /usr/include/LLVM-12/ (these had some .h files)
So I tried writing some passes; created an out-of-tree build using the answer given here:
Facing issue with makefile for Hello pass in llvm
But when I ran the make, it gave me this error:
/usr/include/llvm-12/llvm/Pass.h:337:10: fatal error: llvm/PassAnalysisSupport.h: No file or directory
337 | #include "llvm/PassAnalysisSupport.h"
|
compilation terminated.
So I checked /usr/include/llvm-12/llvm/ and found that Pass.h and PassAnalysisSupport.h both were present in the current directory, so shouldn't the Pass.h file have #include "PassAnalysisSupport.h" instead of the present #include "llvm/PassAnalysisSupport.h"?
I also checked the code for Pass.h online and it also had #include "llvm/PassAnalysisSupport.h". Other header files in the llvm directory also used the same format #include "llvm/<name>"
So what is going on here, who messed up, the devs or my llvm.sh (also the devs) or the problem is something else?
Any help would be appreciated (Im using Mint MATE 20.2 if thats relevant)
Source file (headers; firstpass/first/fpass.cpp):
#include <llvm-12/llvm/Pass.h>
#include <llvm-12/llvm/IR/Function.h>
#include <llvm-12/llvm/Support/raw_ostream.h>
#include <llvm-12/llvm/IR/LegacyPassManager.h>
#include <llvm-12/llvm/Transforms/IPO/PassManagerBuilder.h>
(firstpass/CMakeLists.txt):
find_package(LLVM REQUIRED CONFIG)
include_directories($(LLVM_INCLUDE_DIRS))
add_subdirectory(first)
(firstpass/first/CMakeLists.txt):
add_library(LLVMfirst MODULE fpass.cpp)

clang++ compiles an executable, but clang-check cannot find std header

I have a test cmake C++ app, that I can compile successfully with clang++-10 on Ubuntu 20.04 (with all that CMAKE_USER_MAKE_RULES_OVERRIDE machinery).
The layout of the cmake project is:
./test.cpp
./CMakeLists.txt
./build
I also create the build database json file with CMAKE_EXPORT_COMPILE_COMMANDS inside ./build (this json file is necessary for the clang-check operation AFAIU).
Now, launched from the build dir, the check invocation fails:
clang-check-10 --analyze ../test.cpp
<projDir>/test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Error while processing <projDir>/test.cpp.
Any ideas how to fix this?
Edit: Have also tried specifying -p=$(pwd) to clang-check, but it still could not find the header.
clang-check is not a compiler. It's used for checking error in AST, and in this case it can't find the system header in your code. Add '--' in the end of line to ignore it.
clang-check-10 --analyze ../test.cpp
For more information: ClangCheck on LLVM

cmake configure_file just for update a line not over-writing the whole file

I know that we can configure a file using cmake as discussed in Can CMake generate configure file? for example.
My problem is that I want to update just one line of a file. For instance, assume that this line contains app version:
my_header_version.h.in:
#include "${CMAKE_SOURCE_DIR}/src/definitions.h"
CMakeLists.txt:
...
configure_file(my_header_version.h.in my_header_version.h)
...
my_header_version.h:
#include "/home/myusr/dev/src/definitions.h"
The problem is that if I change my_header_version.h into:
#include <some_lib.h>
#include "/home/myusr/dev/src/definitions.h"
and after that I run cmake .. command, then the line #include <some_lib.h> gets lost.
What should I do if I want to change my_header_version.h directly without changing my_header_version.h.in anytime?!

How to add a dependency to an object file in cmake

So I'm trying to convert a make-based project to cmake, and having trouble wrapping my head around how it works. I've figured out how to get custom commands to generate a header file, and how to compile source file for the target executable, but I can't seem to link them together -- I can't figure out how to trigger the custom command to generate the header file. Here's a trivial example of what I'm trying to do:
CMakeLists.txt:
add_executable(test test.c)
add_custom_command(OUTPUT foo.h
COMMAND echo "/* test */" > foo.h
)
test.c:
#include "foo.h"
int main() { return 0; }
However, when I run cmake and make, it gives me:
/home/cdodd/test/test.c:1:17: fatal error: foo.h: No such file or directory
compilation terminated.
It can't seem to figure out that it needs to create foo.h first before compiling test.c. With make I'd just add a dependency; how do I do that with cmake?
Add the generated file foo.h to the executable target as a dependency:
add_executable(testexe test.c foo.h)
This will make CMake add a file level dependency of the target testexe to the file foo.h in the generated build system.

cuda 5.0 linking with samples .h in Visual Studio 2010

I have visual studio 2010 ultimate and cuda toolkit 5.0. the samples work perfectly. VS recognize cuda`s language, syntax and works fine. but when I tried something like this:
#include <helper_functions.h>
#include <stdio.h>
#include <stdio.h>
int main()
{
return 0;
}
the compiler can't find helper_functions.h (this header file come with the samples and is in C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0\common\inc and my program and the samples aren`t in the same directory.)
when I try with the absolute path:
#include <C:\ProgramData\NVIDIACorporation\CUDASamples\v5.0\common\inc\helper_functions.h>
#include <stdio.h>
int main()
{
return 0;
}
compiler : exception.h no such file or directory
helper_functions.h and exception.h are in the same directory.
I know that I have to link them but I don`t know how do that with VS
You are using visual studio 2010 so you should add the path to your project. Just right click on the name of the project, select properties. under configuration properties select VC++ Directories. add an extra ; at the end of Include Directories and add C:\ProgramData\NVIDIACorporation\CUDASamples\v5.0\common\inc\. also the common directory might also have a lib folder that you should add under Library Directories.
You should do this for each project that needs them. also you can copy them to your VS directory under VC\include.